Question

Difficulty: MediumIAM Policies and Roles

A developer is configuring an AWS Lambda function to process messages from an Amazon SQS queue using an event source mapping. The Lambda function has an execution role with the following permissions policy attached:

{
"Version": "2012-10-17",
"Statement": [
{
"Effect": "Allow",
"Action": [
"sqs:ReceiveMessage",
"sqs:DeleteMessage"
],
"Resource": "arn:aws:sqs:us-east-1:123456789012:ProcessQueue"
}
]
}

When the developer attempts to create the event source mapping, the operation fails with an error indicating that the Lambda function does not have sufficient permissions to read from the queue.

Which of the following actions should the developer take to successfully configure the event source mapping?

  1. Add the "sqs:GetQueueAttributes" action to the statement in the Lambda execution role's permissions policy.Answer
  2. B
    Modify the trust policy of the Lambda execution role to list "sqs.amazonaws.com" as the principal allowed to perform the "sts:AssumeRole" action.
  3. C
    Add a statement to the SQS queue's resource-based policy that allows the Lambda execution role to perform the "sts:AssumeRole" action on the queue.
  4. D
    Modify the Lambda function code to initialize the AWS SDK client by retrieving and hardcoding temporary access keys from the queue's metadata attributes.

Answer

Add the "sqs:GetQueueAttributes" action to the statement in the Lambda execution role's permissions policy.
The correct answer is correct because AWS Lambda requires the `sqs:GetQueueAttributes` permission in addition to `sqs:ReceiveMessage` and `sqs:DeleteMessage` to set up and manage an SQS event source mapping successfully. This permission allows Lambda to read parameters such as the visibility timeout and approximate message count.

Step-by-Step Solution

1
Analyze the error and permissions required for SQS event source mapping.
Identify that Lambda requires three permissions to poll SQS: ReceiveMessage, DeleteMessage, and GetQueueAttributes.
The Lambda service needs to query the queue parameters to scale polling and read messages properly.
2
Compare the current policy with the required permissions list.
The current permissions policy allows only sqs:ReceiveMessage and sqs:DeleteMessage, and is missing sqs:GetQueueAttributes.
This comparison identifies the missing permission cause of the configuration failure.
3
Select the resolution to append the missing permission.
Add the 'sqs:GetQueueAttributes' action to the existing IAM policy attached to the Lambda execution role.
This updates the permissions policy to grant all necessary access for the event source mapping.

Key Concept

Permissions required for SQS event source mappings in Lambda execution roles
Estimated Time:1m 30s
Rate this question