A developer is setting up an AWS Lambda function that needs to retrieve and write items to an Amazon DynamoDB table in the same AWS account. The developer creates an IAM role named `LambdaDbAccessRole` to be used as the function's execution role. However, when attempting to save the Lambda function configuration, the developer receives an error stating that the AWS Lambda service is not authorized to assume the role. The developer checks the trust policy currently attached to `LambdaDbAccessRole` and finds the following document:
{
"Version": "2012-10-17",
"Statement": [
{
"Effect": "Allow",
"Action": [
"dynamodb:GetItem",
"dynamodb:PutItem"
],
"Resource": "arn:aws:dynamodb:us-east-1:123456789012:table/Products"
}
]
}
How should the developer resolve this issue to allow the Lambda function to execute and interact with the DynamoDB table?
- Update the trust policy of `LambdaDbAccessRole` to allow the `lambda.amazonaws.com` service principal to perform the `sts:AssumeRole` action, and attach a separate identity-based permissions policy containing the DynamoDB actions to the role.Cevap
- BModify the trust policy of `LambdaDbAccessRole` to add `"Principal": { "Service": "lambda.amazonaws.com" }` and `"Action": "sts:AssumeRole"` to the existing statement alongside the DynamoDB actions.
- CConfigure the Lambda function to bypass the execution role by embedding the AWS access key and secret key of an IAM user with DynamoDB permissions directly in the function code.
- DCreate a resource-based policy on the DynamoDB table that grants permission to `lambda.amazonaws.com` and use the AWS Account root user credentials to run the Lambda function.