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

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • MyrinNew
    Senior Member
    • Feb 2024
    • 5168

    #1

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

    🎯 Scenario

    You deployed a backend API (FastAPI / Node / Java β€” doesn’t matter) on:
    • AWS ECS / EKS / EC2
    • Behind Load Balancer


    Example API:














    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













    πŸ”Ή Kubernetes (Ingress)













    πŸ”Ή API Gateway













    πŸ‘‰ This URL = your entry point





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

    Typical endpoints:


    /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"
    }










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

    Request:





    GET {{base_url}}/health







    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");
    });










    πŸ‘‰ DevOps meaning:
    • Used in Load Balancer health checks
    • Used in Kubernetes readiness/liveness probes





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

    Request:





    POST {{base_url}}/login







    Body:





    {
    "username": "admin",
    "password": "password123"
    }










    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);










    πŸ‘‰ DevOps meaning:
    • Verifies authentication service
    • Detects broken IAM / auth integration





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

    Request:





    GET {{base_url}}/users







    Headers:





    Authorization: Bearer {{auth_token}}










    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);
    });










    πŸ‘‰ DevOps checks:
    • Token works
    • Backend connected to DB
    • No 500 errors





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

    Request:





    GET {{base_url}}/users







    (no headers)





    Tests:





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










    πŸ‘‰ DevOps meaning:
    • Security validation
    • Prevents open APIs





    ⚑ TEST 5 β€” PERFORMANCE CHECK





    pm.test("Response time ", function () {
    pm.expect(pm.response.responseTime).to.be.below(30 0);
    });










    πŸ‘‰ DevOps meaning:
    • Detect slow deployments
    • Catch DB/network issues





    πŸ’£ TEST 6 β€” FAILURE SIMULATION

    Request:





    GET {{base_url}}/crash







    Tests:





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










    πŸ‘‰ 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










    πŸ”₯ 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










    πŸ’£ 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







    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




    More...
Working...