AWS Certified Developer – Associate / Question #922 of 557

Question #922

A developer is creating an AWS Lambda function that is invoked by messages from an Amazon Simple Notification Service (Amazon SNS) topic. The messages represent user profile updates from a social media platform. The developer wants the Lambda function to process only the messages that pertain to phone number changes. Additional subscribers to the SNS topic will process any other messages. Which solution will meet these requirements in the LEAST development effort?

A

Use Lambda event filtering to allow only messages that are related to phone number changes to invoke the Lambda function.

B

Use an SNS filter policy on the Lambda function subscription to allow only messages that are related to phone number changes to invoke the Lambda function.

C

Subscribe an Amazon Simple Queue Service (Amazon SQS) queue to the SNS topic. Configure the SQS queue with a filter policy to allow only messages that are related to phone number changes. Connect the SQS queue to the Lambda function.

D

Configure the Lambda code to check the received message. If the message is not related to a phone number change, configure the Lambda function to publish the message back to the SNS topic for the other subscribers to process.

Explanation

Answer B is correct because Amazon SNS supports subscription filter policies, which allow subscribers (like the Lambda function) to define criteria for the messages they receive. By configuring a filter policy on the Lambda's SNS subscription, only messages matching the phone number change criteria are sent to the Lambda function. This approach requires minimal effort as it leverages native SNS functionality without code changes or additional infrastructure.

Other options are less efficient:
- A: Lambda event filtering is not applicable to SNS-triggered Lambdas; SNS uses subscription filters instead.
- C: Adding an SQS queue introduces unnecessary complexity since SNS filtering can be applied directly to the Lambda subscription.
- D: Modifying Lambda code to filter and republish messages increases development effort and potential errors.

Answer

The correct answer is: B