DVA-C02 Question 375
Select 3A developer is working on a serverless application deployed using AWS Lambda. The application processes incoming messages from an Amazon SQS queue and logs metrics for debugging and monitoring purposes. The developer needs to implement custom application-level metrics, such as the number of successfully processed messages and processing latency, and make these metrics visible in Amazon CloudWatch. Which of the following steps should the developer take to implement custom metrics?
- A
Use the AWS SDK to publish custom metrics to CloudWatch using the PutMetricData API.
- B
Use embedded metrics by including the metrics in JSON format within the Lambda function's logs, and enable the CloudWatch Embedded Metric Format.
- C
Enable AWS X-Ray tracing for the Lambda function to automatically track custom application metrics.
- D
Use the CloudWatch Agent to collect and publish metrics directly from the Lambda function.
- E
Attach an IAM policy to the Lambda execution role that allows the 'cloudwatch:PutMetricData' action.
Show answer and explanation
Correct answers: A, B, E
Explanation
To implement custom metrics in a Lambda-based application, developers can either use the PutMetricData API to send metrics directly to CloudWatch or use embedded metrics by including them in logs processed by CloudWatch with the Embedded Metric Format. Additionally, the Lambda execution role must have appropriate permissions (e.g., 'cloudwatch:PutMetricData') to publish metrics to CloudWatch. AWS X-Ray and the CloudWatch Agent are not suitable for publishing custom application-level metrics in this scenario.
- A. Correct.
Correct. The PutMetricData API allows publishing custom metrics to CloudWatch. This is a standard method for sending application-specific metrics.
- B. Correct.
Correct. Embedded metrics enable you to include custom metrics within your application logs, and CloudWatch automatically extracts these metrics when the Embedded Metric Format is enabled.
- C. Incorrect.
Incorrect. AWS X-Ray is used for distributed tracing and debugging; it does not automatically track or publish custom application metrics to CloudWatch.
- D. Incorrect.
Incorrect. The CloudWatch Agent is designed for EC2 or on-premises servers, not for Lambda functions.
- E. Correct.
Correct. The Lambda execution role must include permissions to use the 'cloudwatch:PutMetricData' action for the function to publish metrics to CloudWatch.