A developer is configuring an AWS Lambda function in AWS account to retrieve data from an Amazon S3 bucket. The function is assigned an IAM role named `LambdaS3ReaderRole`. The developer has already attached a permissions policy to this role that allows `s3:GetObject` on the target bucket. However, when the Lambda function runs, it fails with an authorization error indicating that the AWS Lambda service is not authorized to assume the role.
The developer inspects the trust policy of `LambdaS3ReaderRole` and finds the following configuration:
{
"Version": "2012-10-17",
"Statement": [
{
"Effect": "Allow",
"Principal": {
"Service": "lambda.amazonaws.com"
},
"Action": "s3:GetObject",
"Resource": "arn:aws:s3:::my-app-data-bucket/*"
}
]
}
Which modification to the trust policy is required to resolve this error?
- AChange the Action element to "sts:AssumeRole" but keep the Resource element set to "arn:aws:s3:::my-app-data-bucket/*".
- BChange the Principal element to "AWS": "arn:aws:iam::987654321098:root" and add the Lambda function ARN to the Resource element.
- Change the Action element to "sts:AssumeRole" and remove the Resource element.Cevap
- DModify the Lambda function code to initialize the Amazon S3 client with the access key and secret access key of an IAM user that has S3 permissions, bypassing the role trust policy.