Learn how to use AWS Lambda and Amazon SNS to handle external API errors in your serverless application. Find out how to publish custom metrics, configure CloudWatch alarms, and send notifications to your support team.
Table of Contents
Question
A company is building a serverless application on AWS. The application uses an AWS Lambda function to process customer orders 24 hours a day, 7 days a week. The Lambda function calls an external vendor’s HTTP API to process payments.
During load tests, a developer discovers that the external vendor payment processing API occasionally times out and returns errors. The company expects that some payment processing API calls will return errors.
The company wants the support team to receive notifications in near real time only when the payment processing external API error rate exceed 5% of the total number of transactions in an hour. Developers need to use an existing Amazon Simple Notification Service (Amazon SNS) topic that is configured to notify the support team.
Which solution will meet these requirements?
A. Write the results of payment processing API calls to Amazon CloudWatch. Use Amazon CloudWatch Logs Insights to query the CloudWatch logs. Schedule the Lambda function to check the CloudWatch logs and notify the existing SNS topic.
B. Publish custom metrics to CloudWatch that record the failures of the external payment processing API calls. Configure a CloudWatch alarm to notify the existing SNS topic when error rate exceeds the specified rate.
C. Publish the results of the external payment processing API calls to a new Amazon SNS topic. Subscribe the support team members to the new SNS topic.
D. Write the results of the external payment processing API calls to Amazon S3. Schedule an Amazon Athena query to run at regular intervals. Configure Athena to send notifications to the existing SNS topic when the error rate exceeds the specified rate.
Answer
B. Publish custom metrics to CloudWatch that record the failures of the external payment processing API calls. Configure a CloudWatch alarm to notify the existing SNS topic when error rate exceeds the specified rate.
Explanation
The correct answer is B. Publish custom metrics to CloudWatch that record the failures of the external payment processing API calls. Configure a CloudWatch alarm to notify the existing SNS topic when the error rate exceeds the specified rate.
This solution will meet the requirements because it allows for monitoring the error rate of the external vendor’s payment processing API and notifying the support team only when the error rate exceeds 5% of the total number of transactions in an hour. By publishing custom metrics to CloudWatch for each failure, the company can track the performance of the external API over time. A CloudWatch alarm can be set up based on these metrics to trigger a notification to an existing Amazon SNS topic, which is already configured to alert the support team. This approach provides near real-time monitoring and notification with minimal operational overhead.
The other options are not as suitable because:
- Option A: Using CloudWatch Logs Insights to query logs and scheduling a Lambda function to check logs and notify SNS is a more complex solution that may not provide notifications in near real-time due to the scheduled nature of log checks.
- Option C: Publishing results to a new SNS topic and subscribing support team members does not leverage the existing notification infrastructure and does not provide a mechanism for calculating error rates.
- Option D: Writing results to Amazon S3 and scheduling Amazon Athena queries introduces unnecessary complexity and potential delays in notification due to query run times and scheduling intervals.
Therefore, option B is the best solution for achieving the desired outcome with efficiency and effectiveness.
The latest AWS Certified Developer – Associate DVA-C02 certification actual real practice exam question and answer (Q&A) dumps are available free, which are helpful for you to pass the AWS Certified Developer – Associate DVA-C02 exam and earn AWS Certified Developer – Associate DVA-C02 certification.