- Create a simple Lambda function (Python runtime) named
xray-demo. - Enable Lambda service tracing so the function can send traces to X-Ray.
- Invoke the function with test events to generate traces.
- Inspect traces, metrics, and logs in the X-Ray console.
Quick summary of steps
1. Create the Lambda function
- In the AWS Lambda console choose Create function.
- Select Author from scratch, name the function
xray-demo, choose a Python runtime (for example Python 3.9), and accept the defaults. - Create the function and wait for the function configuration page to load.

2. Enable X‑Ray tracing for the function
- On the
xray-demofunction page open the Configuration tab. - Scroll to Monitoring and Operations Tools and click Edit.
- Under Additional monitoring tools enable Lambda service traces (optionally enable Application Signals), then click Save.

Enabling tracing from the Lambda console will automatically update the function’s execution role to include permissions required to send trace data to X‑Ray. If your role is immutable or restricted (for example, due to permission boundaries), attach the AWS managed policy
AWSXRayDaemonWriteAccess (or an equivalent policy) to the function’s execution role manually.3. Create a test event and invoke the function
- Open the Test tab for the Lambda function.
- Create a new test event (for example name it
X-Ray test) and use a simple JSON payload. The default sample event works fine:
- Save the test event and invoke the function multiple times to generate trace data. Each invocation returns a response and basic console log similar to:

4. Open the X‑Ray console and inspect traces
- Open CloudWatch X‑Ray in a new browser tab and allow it to load.
- Switch between the Map and List views:
- Map view visualizes services and request flow between them.
- List view shows individual trace segments and allows you to open detailed trace records.

5. Review metrics and traced requests
Use the metrics panels to inspect latency, request rates, and faults over time. These metrics give you a high‑level view before you drill into individual traces.
6. View the traces list
The Traces table lists individual trace IDs, timestamps, HTTP/status codes, and durations. Each entry corresponds to a Lambda invocation you performed earlier.
7. Select an individual trace to see details
Opening a trace shows a detailed view with segments for the Lambda service and the function invocation, response codes, durations, and any annotations or metadata. From here you can jump to related logs. Example trace segment selector:
8. View logs associated with a trace
X‑Ray includes a Logs section that links to CloudWatch Logs for the trace. Typical Lambda log entries look like:Troubleshooting and tips
If you don’t see traces after invoking the function:
- Confirm that Lambda service traces is enabled in the function configuration.
- Verify the function’s execution role has
AWSXRayDaemonWriteAccess(or equivalent) permissions. - Wait a minute; traces can take a short time to appear in X‑Ray.
Conclusion
After enabling X‑Ray traces and invokingxray-demo a few times, traces will appear in the X‑Ray console. Use the Map and List views to analyze request flows, detect latency hotspots, and identify errors. From a trace you can jump directly to logs for deeper investigation.
For richer, in‑code tracing (custom subsegments, annotations, and metadata), instrument your Lambda function using the AWS X‑Ray SDK and follow the AWS X‑Ray Developer Guide:
- AWS X‑Ray Developer Guide: https://docs.aws.amazon.com/xray/latest/devguide/