AWS Certified Developer – Associate — Question 186
A company has an AWS Lambda function that runs hourly, reads log files that are stored in Amazon S3, and forwards alerts to Amazon Simple Notification Service (Amazon SNS) topics based on content. A developer wants to add a custom metric to the Lambda function to track the number of alerts of each type for each run. The developer needs to log this information in Amazon CloudWatch in a metric that is named Lambda/AlertCounts.
How should the developer modify the Lambda function to meet this requirement with the LEAST operational overhead?
Answer options
- A. Add a print statement to standard out for each alert and the number of occurrences.
- B. Add a call to the PutMetricData API operation. Pass an array for alerts and the number of occurrences in the Values and Counts fields with a namespace of “Lambda/AlertCounts”.
- C. Add a call to the PutMetricAlarm API operation. Pass an array of alerts in the metrics member with the namespace of “Lambda/AlertCounts”.
- D. Add a call to the PutDashboard API operation. Pass an array of alerts in the metrics member with the namespace of “Lambda/AlertCounts”.
Correct answer: B
Explanation
The correct answer is B because the PutMetricData API operation is specifically designed for publishing custom metrics to CloudWatch, allowing the developer to log the number of alerts efficiently. Option A merely prints information without logging it as a metric, while Options C and D involve operations that do not directly pertain to logging metrics for CloudWatch.