NEXT LEVEL LAB β€” DevOps API Testing (AWS + Auth + CI/CD mindset)

dev.to

🎯 Scenario

You deployed a backend API (FastAPI / Node / Java β€” doesn’t matter) on:

  • AWS ECS / EKS / EC2
  • Behind Load Balancer

Example API:

http://your-api-alb.amazonaws.com
Enter fullscreen mode Exit fullscreen mode

You must:

  • Verify it works
  • Validate authentication
  • Test protected endpoints
  • Catch failures BEFORE deployment

🧠 PART 1 β€” WHERE API IS LOCATED (REAL WORLD)

In real DevOps:

πŸ”Ή AWS ECS / ALB

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

πŸ”Ή Kubernetes (Ingress)

http://api.mycompany.com
Enter fullscreen mode Exit fullscreen mode

πŸ”Ή API Gateway

https://abc123.execute-api.us-east-1.amazonaws.com/prod
Enter fullscreen mode Exit fullscreen mode

πŸ‘‰ This URL = your entry point


🧠 PART 2 β€” API STRUCTURE (REAL APP)

Typical endpoints:

Endpoint Purpose
/health Health check
/login Auth
/users Data
/orders Business logic

πŸš€ PART 3 β€” BUILD REAL POSTMAN COLLECTION


πŸ“ ENVIRONMENT

{"base_url":"http://your-api-alb.amazonaws.com"}
Enter fullscreen mode Exit fullscreen mode

βœ… TEST 1 β€” HEALTH CHECK (CRITICAL)

Request:

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

Tests:

pm.test("Service is UP", function () {
    pm.response.to.have.status(200);
});

pm.test("Response contains status OK", function () {
    const json = pm.response.json();
    pm.expect(json.status).to.eql("ok");
});
Enter fullscreen mode Exit fullscreen mode

πŸ‘‰ DevOps meaning:

  • Used in Load Balancer health checks
  • Used in Kubernetes readiness/liveness probes

βœ… TEST 2 β€” LOGIN (AUTHENTICATION)

Request:

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

Body:

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

Tests:

const json = pm.response.json();

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

pm.test("Token received", function () {
    pm.expect(json.token).to.exist;
});

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

πŸ‘‰ DevOps meaning:

  • Verifies authentication service
  • Detects broken IAM / auth integration

βœ… TEST 3 β€” PROTECTED API (VERY IMPORTANT)

Request:

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

Headers:

Authorization: Bearer {{auth_token}}
Enter fullscreen mode Exit fullscreen mode

Tests:

pm.test("Authorized access", function () {
    pm.response.to.have.status(200);
});

pm.test("Users returned", function () {
    const json = pm.response.json();
    pm.expect(json.length).to.be.above(0);
});
Enter fullscreen mode Exit fullscreen mode

πŸ‘‰ DevOps checks:

  • Token works
  • Backend connected to DB
  • No 500 errors

❌ TEST 4 β€” SECURITY TEST (NO TOKEN)

Request:

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

(no headers)


Tests:

pm.test("Unauthorized access blocked", function () {
    pm.response.to.have.status(401);
});
Enter fullscreen mode Exit fullscreen mode

πŸ‘‰ DevOps meaning:

  • Security validation
  • Prevents open APIs

⚑ TEST 5 β€” PERFORMANCE CHECK

pm.test("Response time < 300ms", function () {
    pm.expect(pm.response.responseTime).to.be.below(300);
});
Enter fullscreen mode Exit fullscreen mode

πŸ‘‰ DevOps meaning:

  • Detect slow deployments
  • Catch DB/network issues

πŸ’£ TEST 6 β€” FAILURE SIMULATION

Request:

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

Tests:

pm.test("Server should not crash", function () {
    pm.expect(pm.response.code).to.not.eql(500);
});
Enter fullscreen mode Exit fullscreen mode

πŸ‘‰ DevOps:

  • Catch backend crashes early

πŸš€ PART 4 β€” AUTOMATION (REAL PIPELINE)


Export:

  • collection.json
  • environment.json

Run with Newman:

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

πŸ”₯ CI/CD PIPELINE EXAMPLE (REAL)

name: API Tests

on: [push]

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 FAILURE SCENARIO

If:

  • /health fails β†’ service DOWN
  • /login fails β†’ auth broken
  • /users fails β†’ DB broken

πŸ‘‰ Pipeline = ❌ FAIL
πŸ‘‰ Deployment = ❌ STOP


🧠 PART 5 β€” HOW DEVOPS DEBUGS

If test fails:

Step 1:

curl http://api-url/health
Enter fullscreen mode Exit fullscreen mode

Step 2:

Check logs:

  • ECS β†’ CloudWatch
  • Kubernetes β†’ kubectl logs
  • EC2 β†’ /var/log

Step 3:

Check:

  • Security groups
  • DB connection
  • Env variables

🧠 PART 6 β€” REAL INTERVIEW ANSWER

πŸ‘‰ Question:
"How do you validate API in DevOps?"

Answer:

I validate API using Postman collections with automated tests for health checks, authentication, authorization, and response validation. Then I run them using Newman in CI/CD pipelines to ensure deployments do not break backend services.


You now understand:

βœ” Where API lives (ALB, EKS, API Gateway)
βœ” How to find endpoints
βœ” What DevOps tests (NOT QA level)
βœ” Auth + security testing
βœ” Performance checks
βœ” CI/CD automation
βœ” Failure handling

Read Full Article open_in_new
arrow_back Back to News