Learn how to monitor payment processing errors in a serverless application and trigger notifications using CloudWatch alarms and Amazon SNS topics.
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 error rate exceeds the specified rate.
The reason is that CloudWatch is a monitoring and observability service that can collect and track metrics, logs, events, and alarms for AWS resources and applications. CloudWatch can also publish custom metrics that are defined by the user, such as the number of failures or errors of an API call. Custom metrics can be used to monitor the performance and availability of the application and trigger actions based on predefined thresholds or conditions.
To meet the requirements, the developer can publish custom metrics to CloudWatch that record the failures of the external payment processing API calls. The developer can use the AWS SDK for the programming language or the CloudWatch API to put custom metrics data points to CloudWatch from within the Lambda function. The developer can also use dimensions to add metadata to the custom metrics, such as the name of the external API or the type of error.
The developer can then configure a CloudWatch alarm to notify the existing SNS topic when error rate exceeds the specified rate. A CloudWatch alarm is an action that CloudWatch performs when a metric meets a specified threshold over a specified number of time periods. The developer can specify the custom metric, the statistic (such as average, sum, or count), the threshold (such as greater than 5%), and the period (such as one hour) for the alarm. The developer can also specify the existing SNS topic as the action for the alarm, which will send notifications to the support team members who are subscribed to the topic.
Therefore, publishing custom metrics to CloudWatch that record the failures of the external payment processing API calls and configuring a CloudWatch alarm to notify the existing SNS topic when error rate exceeds the specified rate will meet these requirements.
The other options are incorrect because they are not efficient, reliable, or scalable:
A. Writing the results of payment processing API calls to CloudWatch logs and using CloudWatch Logs Insights to query the logs is not efficient or reliable. CloudWatch logs is a service that can store and monitor log data from AWS resources and applications. CloudWatch Logs Insights is a feature that can perform queries and analysis on log data. However, this option requires writing additional code to write and query the logs, which can increase the complexity and cost of the application. Moreover, this option relies on scheduling the Lambda function to check the logs periodically, which can introduce delays or inconsistencies in sending notifications.
C. Publishing the results of the external payment processing API calls to a new SNS topic and subscribing the support team members to the new SNS topic is not efficient or scalable. SNS is a service that can deliver messages to multiple subscribers using topics. However, this option requires creating a new SNS topic and managing multiple subscriptions for each support team member, which can increase the overhead and cost of the application. Moreover, this option does not filter out the notifications based on error rate or time period, which can result in too many notifications or false alarms.
D. Writing the results of the external payment processing API calls to S3 and scheduling an Athena query to run at regular intervals is not efficient or reliable. S3 is a service that can store any amount of data in objects. Athena is a service that can perform interactive queries on data stored in S3 using standard SQL. However, this option requires writing additional code to write and query the data, which can increase the complexity and cost of the application. Moreover, this option relies on scheduling the Athena query to run periodically, which can introduce delays or inconsistencies in sending notifications.
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.