AWS Lambda Logging, Monitoring, and Tracing
Logging with CloudWatch Logs
- Lambda functions automatically store execution logs in CloudWatch Logs.
- Requires Lambda execution role with IAM policy authorizing write access to CloudWatch Logs.
- Included in the Lambda basic execution role.
Monitoring with CloudWatch Metrics
- Metrics are available in the CloudWatch Metrics UI or Lambda UI.
- Key metrics include:
- Invocations: The number of times your function is invoked.
- Duration: The execution time of your function.
- Concurrent Executions: The number of instances serving requests at a given time.
- Error Counts: The number of errors thrown by your function.
- Success Rate: The percentage of successful invocations.
- Throttles: The number of Lambda invocation attempts that were throttled.
- Async Delivery Failures: Failures in asynchronous invocation.
- Iterator Age (for Kinesis/DynamoDB streams): The age of the last record processed.
Tracing with AWS X-Ray
- Enable active tracing in Lambda configuration to use X-Ray.
- Requires the Lambda function to have the correct IAM execution role for X-Ray.
- Managed policy for X-Ray:
AWSXRayDaemonWriteAccess.
- Important environment variables:
AWS_XRAY_DAEMON_ADDRESS: IP and port of the X-Ray daemon.
- Other X-Ray related environment variables should be recognized.
What is the X-Ray Daemon?
- Role: The X-Ray daemon is a process that runs alongside your Lambda function. It is responsible for:
- Collecting the trace data generated by your function and the X-Ray SDK
- Buffering data locally
- Sending trace data securely to the AWS X-Ray service.
- No direct interaction: You don't need to directly manage or interact with the X-Ray daemon when working with Lambda. AWS handles its execution within the Lambda environment.
Do I need to set up an X-Ray daemon?
- No manual setup: With AWS Lambda, you don't need to set up an X-Ray daemon explicitly. The Lambda service automatically manages an X-Ray daemon process and runs within the Lambda execution environment.
Note for Exam Preparation:
- Remember the environment variable
AWS_XRAY_DAEMON_ADDRESS as it may appear on the exam.