Integrating AWS X-Ray

Objective

Use AWS X-Ray to trace and inspect the entire processing flow of API Gateway → Lambda → DynamoDB.
X-Ray helps visualize traces, latency, errors, and segments/subsegments to ensure the API behaves correctly and efficiently.


Implementation Steps


1. Access IAM Service

  • Go to AWS Console → IAM

XRAY_1

  • Select Roles → LambdaAPIAccessRole

XRAY_2

  • Choose Add permissions → Attach policies → AWSXRayDaemonWriteAccess

XRAY_3


2. Access Lambda

  • Go to AWS Console → Lambda

XRAY_4

  • Select Functions → DynamoDB_API_Handler
  • Go to
    Configuration → Monitoring and operations tools → Additional monitoring tools → Edit

XRAY_5

  • Under Lambda service traces, enable Enable

XRAY_6


3. Access API Gateway

  • Go to AWS Console → API Gateway

XRAY_7

  • Select APIs → FlyoraAPI
  • Go to
    Stages → Logs and tracing → Edit

XRAY_8

  • Check X-Ray tracing

XRAY_9


4. Testing

  • Go to AWS Console → Lambda

XRAY_10

  • In the Test tab, click Create new event

  • Event name: test

  • Paste the JSON below into the event:

    {
    "resource": "/{myProxy+}",
    "path": "/api/v1/bird-types",
    "httpMethod": "GET",
    "headers": {},
    "multiValueHeaders": {},
    "queryStringParameters": {},
    "multiValueQueryStringParameters": {},
    "pathParameters": {},
    "stageVariables": {},
    "requestContext": {
        "identity": {}
    },
    "body": null,
    "isBase64Encoded": false
    }
    
  • Save -> Test

  • Next, go to AWS Console → X-ray XRAY\_11

  • In tab Traces, a new trace ID will appear XRAY\_12

  • Click it to view detailed trace information

XRAY\_13