Question

Difficulty: MediumMessage-Based Integration using Amazon SQS and SNS

An e-commerce order fulfillment system uses an Amazon SQS standard queue to trigger an AWS Lambda function for invoice generation. The third-party invoicing API can take up to 2525 seconds to respond, so the developer configures the Lambda function's timeout to 3030 seconds. During high-traffic periods, customers report receiving duplicate invoices for a single order. Additionally, the developer must ensure that the Lambda function can authenticate with SQS securely without storing access keys in the codebase.

Which two actions should the developer take to resolve the duplication issue and ensure secure credentials management? (Select TWO.)

  1. Increase the visibility timeout of the SQS queue to at least 180180 seconds to prevent message processing overlaps.Answer
  2. Assign an IAM execution role with permissions to access the SQS queue to the Lambda function, and initialize the SQS SDK client without specifying hardcoded credentials.Answer
  3. C
    Decrease the SQS queue's visibility timeout to 1515 seconds to allow other Lambda instances to immediately retry failed invoice generations.
  4. D
    Store the AWS access keys in the Lambda function's environment variables and initialize the SQS SDK client by passing these keys directly into the client constructor.
  5. E
    Extend the Lambda function's timeout to 1010 minutes and cache the processed invoice IDs in a global variable in the execution context to prevent duplicates.

Answer

The developer should increase the SQS queue's visibility timeout to at least 180 seconds and configure the Lambda function with an IAM execution role, initializing the SDK client without hardcoded credentials.
Increasing the SQS visibility timeout to at least 180180 seconds (six times the Lambda function's timeout of 3030 seconds) ensures that the message remains hidden from other consumers for the entire duration of the Lambda function's execution. Using an IAM execution role assigned to the Lambda function allows the AWS SDK to retrieve temporary security credentials from the instance metadata service automatically, preventing credentials from being hardcoded.

Step-by-Step Solution

1
Determine the optimal SQS visibility timeout to prevent duplicates during processing.
Identify that the SQS visibility timeout must be set to at least 66 times the Lambda function timeout plus any batch window. Since the Lambda timeout is 3030 seconds, the visibility timeout should be at least 180180 seconds.
This prevents messages from becoming visible to other pollers while the Lambda function is still executing.
2
Implement a secure credential management strategy for the SQS consumer client.
Configure an IAM role with SQS access permissions and assign it as the Lambda function's execution role, then instantiate the SQS client using default credentials.
This eliminates the need to store AWS access keys in the codebase or configuration environment variables.

Key Concept

Configuring SQS visibility timeout to match Lambda execution limits and implementing IAM-based SDK authentication.
Estimated Time:1m 30s
Rate this question