Question

Difficulty: MediumMessage-Based Integration using Amazon SQS and SNS

A developer is implementing a microservice that processes message batches from an Amazon SQS queue. The processing logic is deployed as an AWS Lambda function with a timeout of 55 minutes. However, the developer notices that some message batches are processed multiple times, and the application logs show that the Lambda function is frequently terminated prematurely. Additionally, the Lambda function code currently initializes the SQS client by passing hardcoded IAM credentials.

Which of the following actions should the developer take to resolve these issues? (Select TWO.)

  1. Remove the hardcoded credentials from the SDK client initialization and associate an IAM execution role containing SQS permissions with the Lambda function.Answer
  2. Increase the Lambda function's timeout to exceed the maximum processing time, and set the SQS queue's visibility timeout to at least 66 times the Lambda function's timeout.Answer
  3. C
    Decrease the SQS queue's visibility timeout to 3030 seconds so that messages can be quickly picked up by other concurrent Lambda executions.
  4. D
    Re-initialize the SQS client inside the Lambda handler function on every invocation to guarantee that execution context variables are cleared after each run.
  5. E
    Pass the IAM access key and secret access key directly to the SQS client constructor in the code, using the default credential provider chain as a fallback.

Answer

The developer should remove the hardcoded credentials from the SDK client initialization and associate an IAM execution role containing SQS permissions with the Lambda function, while also increasing the Lambda function's timeout to exceed the maximum processing time and setting the SQS queue's visibility timeout to at least 66 times the Lambda function's timeout.
To secure the function, the developer should associate an IAM execution role with the Lambda function and remove hardcoded credentials from the SDK client. To resolve the timeouts and duplicates, the developer should increase the Lambda timeout to accommodate the processing duration and set the SQS queue's visibility timeout to at least 66 times the Lambda function's timeout, which is the AWS recommended ratio for SQS-Lambda integrations.

Step-by-Step Solution

1
Analyze the log files to diagnose the root causes: Lambda function premature termination and message duplication.
Identify that the Lambda function requires more than 55 minutes to complete processing, causing a timeout, which leads SQS to make the message visible to other consumers again.
This establishes that both the Lambda timeout and the SQS visibility timeout must be adjusted.
2
Address the security issue in the SDK configuration.
Remove the hardcoded IAM access keys from the code and assign an IAM execution role with the required SQS policies directly to the Lambda function.
To ensure secure credential management via AWS STS temporary credentials.
3
Adjust SQS and Lambda timeouts based on processing requirements.
Increase the Lambda function timeout (e.g., to 1010 minutes) to allow complete execution, and configure the SQS queue's visibility timeout to at least 66 times that value.
To prevent duplicate processing by ensuring the message remains invisible to other consumers during processing.

Key Concept

Integrating Amazon SQS with AWS Lambda, managing visibility timeouts, and securing SDK clients using IAM execution roles.
Rate this question