Test API Endpoints

Step 1: Test from API Gateway Console

1.1. Test GET /users

  1. Go to API Gateway Console → Select daivietblood-api
  2. Select /usersGET
  3. Click Test
  4. Click Test button

Expected response:

{
  "statusCode": 200,
  "body": "[]"
}

Step 2: Test with cURL

Replace YOUR_API_URL with your actual Invoke URL.

2.1. Create a User (POST /users)

curl -X POST https://YOUR_API_URL/prod/users \
  -H "Content-Type: application/json" \
  -d '{
    "email": "nguyen.van.a@example.com",
    "name": "Nguyen Van A",
    "blood_type": "O+",
    "phone": "0901234567"
  }'

Expected response:

{
  "id": 1,
  "email": "nguyen.van.a@example.com",
  "name": "Nguyen Van A",
  "blood_type": "O+",
  "phone": "0901234567"
}

2.2. Get All Users (GET /users)

curl https://YOUR_API_URL/prod/users

Expected response:

[
  {
    "id": 1,
    "email": "nguyen.van.a@example.com",
    "name": "Nguyen Van A",
    "blood_type": "O+",
    "phone": "0901234567",
    "created_at": "2025-12-09T10:00:00.000Z"
  }
]

2.3. Create Emergency Request (POST /emergency-requests)

curl -X POST https://YOUR_API_URL/prod/emergency-requests \
  -H "Content-Type: application/json" \
  -d '{
    "requester_name": "Benh vien Cho Ray",
    "blood_type": "AB-",
    "units_needed": 5,
    "hospital": "Cho Ray Hospital",
    "urgency": "critical"
  }'

Expected response:

{
  "id": 1,
  "message": "Emergency request created"
}

2.4. Get Emergency Requests (GET /emergency-requests)

curl https://YOUR_API_URL/prod/emergency-requests

Step 3: Test with Postman

  1. Open Postman
  2. Create new Collection: DaiVietBlood API
  3. Add requests:
Request NameMethodURL
Get UsersGET{{baseUrl}}/users
Create UserPOST{{baseUrl}}/users
Get Emergency RequestsGET{{baseUrl}}/emergency-requests
Create Emergency RequestPOST{{baseUrl}}/emergency-requests
  1. Set Collection variable:
    • baseUrl: https://YOUR_API_URL/prod

Step 4: Verify Lambda Logs

  1. Go to CloudWatch ConsoleLog groups

  2. Find log groups:

    • /aws/lambda/daivietblood-get-users
    • /aws/lambda/daivietblood-create-user
    • /aws/lambda/daivietblood-emergency-requests
  3. Check recent log streams for:

    • Successful invocations
    • Any errors or exceptions
    • Database connection logs

Common Issues & Solutions

IssueCauseSolution
502 Bad GatewayLambda errorCheck CloudWatch logs for details
TimeoutLambda cannot reach RDSVerify VPC, Subnets, Security Groups
CORS errorCORS not configuredEnable CORS on API Gateway
500 Internal Server ErrorDatabase connection failedCheck DB credentials in environment variables

Step 5: Performance Check

  1. Note the response time for each API call
  2. First call may be slow (Lambda cold start)
  3. Subsequent calls should be faster

Expected performance:

EndpointCold StartWarm
GET /users~3-5s~200-500ms
POST /users~3-5s~200-500ms
GET /emergency-requests~3-5s~200-500ms

💡 Tip: Lambda cold start in VPC can be slow. Consider using Provisioned Concurrency for production workloads.


Verification Checklist

  • GET /users returns empty array or user list
  • POST /users creates new user successfully
  • GET /emergency-requests returns requests list
  • POST /emergency-requests creates new request
  • No CORS errors in browser console
  • CloudWatch logs show successful invocations