A developer is configuring an AWS Lambda function in Account A (111122223333) to send logs and processing data directly to an Amazon SQS queue located in Account B (444455556666). The Lambda function is associated with an IAM execution role named LambdaSQSSenderRole. When the Lambda function attempts to call the SQS SendMessage API, it receives an AccessDeniedException. Which two actions are required to resolve this authorization issue and allow the Lambda function to send messages to the queue? (Select two.)
- Attach an IAM policy to the LambdaSQSSenderRole in Account A that allows the sqs:SendMessage action on the ARN of the SQS queue in Account B.Answer
- Configure the queue policy on the SQS queue in Account B to allow the sqs:SendMessage action with the Principal set to the LambdaSQSSenderRole ARN.Answer
- CModify the trust policy of the LambdaSQSSenderRole in Account A to trust the SQS service principal (sqs.amazonaws.com).
- DConfigure the Lambda function environment variables to store hardcoded AWS access keys of an IAM user in Account B who has access to the queue, and use them to initialize the AWS SDK client.
- EUpdate the SQS queue policy in Account B to set the Principal to the Account A ID and set the Resource block to the ARN of the LambdaSQSSenderRole.
Answer
Attach an IAM policy to the LambdaSQSSenderRole in Account A that allows the sqs:SendMessage action on the ARN of the SQS queue in Account B, and configure the queue policy on the SQS queue in Account B to allow the sqs:SendMessage action with the Principal set to the LambdaSQSSenderRole ARN.
For cross-account access to resource-based services like SQS, permissions must be granted on both sides. The caller in Account A (the Lambda execution role) must be allowed by its identity policy to send messages to the external queue. Simultaneously, the resource policy in Account B (the SQS queue policy) must allow the execution role from Account A to write to the queue.
Step-by-Step Solution
Key Concept
Cross-account resource access requires authorization in both the source account's identity-based policy and the target account's resource-based policy.