Learn how to build a scalable serverless order processing system using Amazon API Gateway APIs and Lambda functions. Customize APIs for each partner and filter order updates without code changes.
Table of Contents
Question
A company receives food orders from multiple partners. The company has a microservices application that uses Amazon API Gateway APIs with AWS Lambda integration. Each partner sends orders by calling a customized API that is exposed through API Gateway. The API call invokes a shared Lambda function to process the orders.
Partners need to be notified after the Lambda function processes the orders. Each partner must receive updates for only the partner’s own orders. The company wants to add new partners in the future with the fewest code changes possible.
Which solution will meet these requirements in the MOST scalable way?
A. Create a different Amazon Simple Notification Service (Amazon SNS) topic for each partner. Configure the Lambda function to publish messages for each partner to the partner’s SNS topic.
B. Create a different Lambda function for each partner. Configure the Lambda function to notify each partner’s service endpoint directly.
C. Create an Amazon Simple Notification Service (Amazon SNS) topic. Configure the Lambda function to publish messages with specific attributes to the SNS topic. Subscribe each partner to the SNS topic. Apply the appropriate filter policy to the topic subscriptions.
D. Create one Amazon Simple Notification Service (Amazon SNS) topic. Subscribe all partners to the SNS topic.
Answer
C. Create an Amazon Simple Notification Service (Amazon SNS) topic. Configure the Lambda function to publish messages with specific attributes to the SNS topic. Subscribe each partner to the SNS topic. Apply the appropriate filter policy to the topic subscriptions.
Explanation
The correct answer is C. Create an Amazon Simple Notification Service (Amazon SNS) topic. Configure the Lambda function to publish messages with specific attributes to the SNS topic. Subscribe each partner to the SNS topic. Apply the appropriate filter policy to the topic subscriptions. This answer is based on the following reasons:
- Amazon SNS is a fully managed pub/sub messaging service that enables you to decouple and scale microservices, distributed systems, and serverless applications. You can use Amazon SNS to send messages to multiple subscribers, such as email addresses, SMS phone numbers, HTTP endpoints, Lambda functions, or other AWS services.
- Amazon SNS supports message filtering, which allows you to selectively receive messages published to a topic by assigning filter policies to your subscriptions. A filter policy is a JSON object that contains properties that define which messages the subscriber receives. You can use message attributes or message body properties as filters.
- In this scenario, the company receives food orders from multiple partners and needs to notify them after processing the orders. Each partner must receive updates for only their own orders. The company also wants to add new partners in the future with minimal code changes. Therefore, the company can use the following solution:
- Create an Amazon SNS topic and subscribe each partner to the topic. The subscription can be an email address, an SMS phone number, an HTTP endpoint, or any other supported protocol.
- Configure the Lambda function to publish messages with specific attributes or body properties to the SNS topic. For example, the Lambda function can add a partner ID attribute or property to each message that identifies the source of the order.
- Apply the appropriate filter policy to each subscription based on the partner ID attribute or property. For example, the filter policy can be {“partnerID”: [“partnerA”]} for partner A’s subscription and {“partnerID”: [“partnerB”]} for partner B’s subscription.
- When a message is published to the SNS topic, Amazon SNS compares the message attributes or body properties to the filter policies of each subscription. If there is a match, Amazon SNS sends the message to the subscriber. Otherwise, Amazon SNS does not send the message to that subscriber.
- This solution will meet the requirements in the most scalable way because:
- It allows each partner to receive only relevant messages without exposing other partners’ information.
- It reduces the complexity and maintenance of the Lambda function by using a single SNS topic and a single publish operation.
- It enables easy addition of new partners by creating new subscriptions and filter policies without changing the existing code.
The other options are not correct because:
- Option A: Create a different Amazon SNS topic for each partner. Configure the Lambda function to publish messages for each partner to their SNS topic is not a scalable option. This option would require creating and managing multiple SNS topics and multiple publish operations in the Lambda function. It would also increase the cost and complexity of adding new partners in the future.
- Option B: Create a different Lambda function for each partner. Configure the Lambda function to notify each partner’s service endpoint directly is not a scalable option. This option would require creating and managing multiple Lambda functions and multiple service endpoints. It would also introduce tight coupling and dependency between the Lambda functions and the partners’ services.
- Option D: Create one Amazon SNS topic. Subscribe all partners to the SNS topic is not a secure option. This option would send all messages to all partners without any filtering or differentiation. It would expose other partners’ information and violate their privacy.
Therefore, option C is the best answer for this question. I hope this explanation helps you understand how to use Amazon SNS message filtering to selectively notify different subscribers better.
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.