Question

Difficulty: MediumServerless Development with AWS Lambda

An application uses an Amazon SQS queue to receive transaction records. A developer is designing an AWS Lambda function to process these transactions. The Lambda function should only be invoked for messages where the `transactionType` is `refund` and the `amount` is greater than 10001000. The developer wants to minimize Lambda invocation costs. Which of the following steps should the developer take to meet these requirements? (Select two.)

  1. Configure an event source mapping between the SQS queue and the Lambda function.Answer
  2. Specify a FilterCriteria pattern of `{"body": {"transactionType": ["refund"], "amount": [{"numeric": [">", 1000]}]}}` in the event source mapping.Answer
  3. C
    Write custom conditional logic in the Lambda function code to parse the SQS records and exit early if the criteria are not met.
  4. D
    Set the SQS queue's visibility timeout to be shorter than the Lambda function's timeout to automatically discard unqualified messages.
  5. E
    Add a Condition block to the SQS queue access policy to deny SendMessage actions for transactions that do not match the criteria.

Answer

Configure an event source mapping between the SQS queue and the Lambda function, and specify a FilterCriteria pattern of `{"body": {"transactionType": ["refund"], "amount": [{"numeric": [">", 1000]}]}}` in the event source mapping.
The correct options are configuring the event source mapping and applying the filter pattern directly to the JSON message body. By defining a filter pattern in the event source mapping, the Lambda service automatically filters out messages where the transaction type is not a refund or the amount is 10001000 or less. This ensures the Lambda function is only invoked for matching messages, minimizing invocation costs.

Step-by-Step Solution

1
Set up an event source mapping to connect SQS and Lambda.
This establishes the integration, allowing Lambda to poll the queue.
An event source mapping is required for Lambda to consume messages from an SQS queue automatically.
2
Configure FilterCriteria on the event source mapping.
This prevents Lambda from being invoked for messages that do not match the specified pattern.
By applying the filter pattern to the JSON message body, Lambda only charges for invocations of matching messages, minimizing cost.

Key Concept

AWS Lambda Event Source Filtering with Amazon SQS allows filtering of message payloads before invoking the function, reducing cost and processing overhead.
Estimated Time:2m 0s
Rate this question