DEV Community

Aisalkyn Aidarova
Aisalkyn Aidarova

Posted on

ADVANCED LAB β€” AWS REAL PROJECT (ECS + ALB + API + Postman + CI/CD)

🎯 Scenario (REAL COMPANY)

You deployed:

  • Backend API (FastAPI / Node)
  • Running on Amazon ECS
  • Behind Application Load Balancer
  • Logs in Amazon CloudWatch

πŸ‘‰ Your job:
Validate API BEFORE production traffic hits it


🧠 ARCHITECTURE (WHAT YOU ARE TESTING)

User β†’ ALB β†’ ECS Service β†’ Container β†’ Database
Enter fullscreen mode Exit fullscreen mode

Example endpoint:

http://your-alb-123.us-east-1.elb.amazonaws.com
Enter fullscreen mode Exit fullscreen mode

🧠 STEP 1 β€” FIND YOUR API (REAL)

In AWS Console:

  1. Go to ECS
  2. Open your service
  3. Find Load Balancer DNS

πŸ‘‰ This is your API base URL


🧠 STEP 2 β€” DEFINE API CONTRACT (CRITICAL)

Example API:

Endpoint Expected
/health { "status": "ok" }
/login { "token": "..." }
/orders list of orders
/orders/{id} single order

πŸ‘‰ DevOps MUST know expected output (from devs / Swagger)


πŸš€ STEP 3 β€” POSTMAN COLLECTION (PRO LEVEL)


πŸ“ ENVIRONMENT

{
  "base_url": "http://your-alb-url",
  "auth_token": ""
}
Enter fullscreen mode Exit fullscreen mode

βœ… TEST 1 β€” HEALTH CHECK (LOAD BALANCER LEVEL)

GET {{base_url}}/health
Enter fullscreen mode Exit fullscreen mode

Tests:

pm.test("Service is healthy", () => {
    pm.response.to.have.status(200);
});

const json = pm.response.json();

pm.test("Health status OK", () => {
    pm.expect(json.status).to.eql("ok");
});
Enter fullscreen mode Exit fullscreen mode

πŸ‘‰ If FAIL:

  • ECS task crashed
  • Container not running
  • ALB health check failing

πŸ” TEST 2 β€” LOGIN (AUTH FLOW)

POST {{base_url}}/login
Enter fullscreen mode Exit fullscreen mode

Body:

{
  "username": "admin",
  "password": "password"
}
Enter fullscreen mode Exit fullscreen mode

Tests:

const json = pm.response.json();

pm.test("Login success", () => {
    pm.response.to.have.status(200);
});

pm.test("Token exists", () => {
    pm.expect(json.token).to.exist;
});

pm.environment.set("auth_token", json.token);
Enter fullscreen mode Exit fullscreen mode

πŸ‘‰ If FAIL:

  • Auth service broken
  • DB connection issue
  • Env variables missing in ECS

πŸ”₯ TEST 3 β€” CORE BUSINESS API (ORDERS)

GET {{base_url}}/orders
Authorization: Bearer {{auth_token}}
Enter fullscreen mode Exit fullscreen mode

Tests:

pm.test("Orders fetched", () => {
    pm.response.to.have.status(200);
});

const data = pm.response.json();

pm.test("Orders not empty", () => {
    pm.expect(data.length).to.be.above(0);
});
Enter fullscreen mode Exit fullscreen mode

πŸ‘‰ If FAIL:

  • DB not connected
  • Wrong security group
  • Backend error

❌ TEST 4 β€” SECURITY TEST

(no token)

GET {{base_url}}/orders
Enter fullscreen mode Exit fullscreen mode
pm.test("Unauthorized blocked", () => {
    pm.response.to.have.status(401);
});
Enter fullscreen mode Exit fullscreen mode

πŸ‘‰ If FAIL:
🚨 Your API is OPEN β†’ SECURITY ISSUE


⚑ TEST 5 β€” PERFORMANCE CHECK

pm.test("Fast response", () => {
    pm.expect(pm.response.responseTime).to.be.below(400);
});
Enter fullscreen mode Exit fullscreen mode

πŸ‘‰ If FAIL:

  • DB slow
  • Container CPU high
  • Network latency

πŸ’£ TEST 6 β€” FAILURE DETECTION

GET {{base_url}}/orders/999999
Enter fullscreen mode Exit fullscreen mode
pm.test("Handle invalid ID", () => {
    pm.expect(pm.response.code).to.be.oneOf([404, 400]);
});
Enter fullscreen mode Exit fullscreen mode

πŸ‘‰ If FAIL:

  • App not handling errors properly

🚨 STEP 4 β€” REAL DEVOPS DEBUGGING


If /health fails:

Check:

aws ecs list-tasks
aws ecs describe-tasks
Enter fullscreen mode Exit fullscreen mode

Logs:

Check in:
πŸ‘‰ Amazon CloudWatch


Container logs:

Look for:

  • DB connection errors
  • Missing env variables
  • Crash loops

πŸš€ STEP 5 β€” AUTOMATION (CI/CD)


Install Newman:

npm install -g newman
Enter fullscreen mode Exit fullscreen mode

Run:

newman run collection.json -e environment.json
Enter fullscreen mode Exit fullscreen mode

πŸ”₯ GITHUB ACTIONS (REAL)

name: API Validation

on:
  workflow_dispatch:

jobs:
  test-api:
    runs-on: ubuntu-latest

    steps:
      - uses: actions/checkout@v4

      - name: Install Newman
        run: npm install -g newman

      - name: Run API Tests
        run: newman run collection.json -e environment.json
Enter fullscreen mode Exit fullscreen mode

πŸ’£ REAL PRODUCTION FLOW

  1. Developer deploys ECS service
  2. Pipeline runs Postman tests
  3. If ANY fails β†’ ❌ deployment blocked
  4. Fix β†’ redeploy

🧠 WHAT SENIOR DEVOPS DOES HERE

βœ” Validates ALB routing
βœ” Checks ECS tasks health
βœ” Verifies auth + security
βœ” Ensures DB connectivity
βœ” Automates API validation
βœ” Blocks bad deployments


🎯 INTERVIEW LEVEL ANSWER

If asked:

"How do you test APIs in AWS?"

Say:

I retrieve the API endpoint from the Application Load Balancer or API Gateway, validate health endpoints, authentication flows, and protected APIs using Postman. Then I automate these tests using Newman in CI/CD pipelines to ensure that ECS deployments are stable and do not break functionality.

Top comments (0)