This lab is currently in Beta, content may be updated as we refine the material
LABINTERMEDIATE

X-Ray Tracing for Lambda and API Gateway

Deploy a Node.js Lambda function behind API Gateway with X-Ray active tracing, generate real traffic and intentional errors, then use the X-Ray service map and trace timeline to pinpoint the slowest segment and the root cause of a fault.

45 minutes
aws/devops
X-Ray Tracing for Lambda and API Gateway - Platform Engineering Hands-On Lab Icon

Lab Overview

X-Ray is the core distributed tracing service on AWS, and both the DOP-C02 exam and real-world troubleshooting demand that you can configure it end-to-end. Turning on tracing is not enough — you need to know how to read the service map, parse the trace timeline, and isolate exactly which segment caused the problem.

In this lab you will:

  • Create an IAM execution role with Lambda, API Gateway, and X-Ray write permissions
  • Write and deploy a Node.js Lambda function that simulates a multi-phase order-processing pipeline with an intentional 1.5-second payment-processing delay and an error-injection switch
  • Build a REST API Gateway with a `/orders` POST endpoint, wire it to the Lambda, and enable X-Ray on the API stage
  • Generate traffic with `curl`, then use `aws xray get-service-graph` and `batch-get-traces` to locate the slowest segment and measure its contribution to overall latency
  • Inject a fault by submitting an invalid payment amount, trace the error through the service map, and identify the failing subsegment from its fault flag and error metadata
  • Add X-Ray annotations to the Lambda code, create a sampling rule, and confirm that annotations appear in downstream trace views

Everything runs inside a TeKanAid-provisioned AWS lab account using API Gateway (REST), Lambda, X-Ray, CloudWatch Logs, and IAM.

What You'll Learn

Package and deploy a Node.js Lambda function with X-Ray active tracing enabled

Create an IAM execution role that grants Lambda, API Gateway, and X-Ray write permissions

Build a REST API Gateway endpoint integrated with a Lambda function and enable X-Ray on the deployment stage

Use `aws xray get-service-graph` and `aws xray batch-get-traces` to inspect trace data and identify latency bottlenecks and fault segments

Inject a deliberate error and use X-Ray fault flags and error metadata to localize the failing function segment

Add X-Ray annotations to Lambda code and create a sampling rule to control tracing volume

Prerequisites

aws-devops-cli-operations-baseline

basic-iam-and-lambda-familiarity

Technologies Covered

awsxraylambdaapi-gatewaytracingobservabilitysamplingannotationsdop-c02

Part of a Course

This lab is part of the AWS Certified DevOps Engineer - Professional (DOP-C02) course

View All Courses

Choose your plan

Simple, Transparent Pricing

Unlock full access to TeKanAid courses, labs, and bootcamps

MonthlyQuarterly

Pro

Course content without labs

$59/month

Renews automatically. Cancel anytime.

Final price verified at checkout.

  • Full access to all courses
  • Progress tracking
  • Certificate of completion
  • Community access
  • Bootcamp participation
  • New content access
Recommended

Premium

Full access with hands-on labs

$99/month

Renews automatically. Cancel anytime.

Final price verified at checkout.

  • Everything in Pro
  • Unlimited hands-on labs
  • Lab AI Assistant
  • Accelerator bootcamps with live office hours
  • Priority support

Prefer a single course?

Purchase individual courses for a one-time fee of $79. Full access to course content, quizzes, certificates, and community features, lab access is not included.

Browse Courses

Try it free, no credit card

Three free ways to start. All bridge into the paid Premium catalog when you're ready.

Not ready to commit? The crash course is email-only. No academy account required.

Ready to Get Started?

Start this hands-on lab and build real-world Platform Engineering skills

Get Access Now