A developer is implementing a cross-account ingestion pipeline where an AWS Lambda function running in Account A () needs to write files to an Amazon S3 bucket in Account B (). The Lambda function is configured with the execution role `arn:aws:iam::111111111111:role/LambdaExecutionRole`.
To write files, the Lambda function code uses the AWS SDK to assume an IAM role in Account B named `S3WriteRole` (`arn:aws:iam::222222222222:role/S3WriteRole`).
The IAM policy attached to `LambdaExecutionRole` in Account A is:
{
"Version": "2012-10-17",
"Statement": [
{
"Effect": "Allow",
"Action": "sts:AssumeRole",
"Resource": "arn:aws:iam::222222222222:role/S3WriteRole"
}
]
}
When the Lambda function executes, the `sts:AssumeRole` API call fails with an `AccessDenied` error. The developer inspects the trust policy of `S3WriteRole` in Account B, which is currently configured as follows:
{
"Version": "2012-10-17",
"Statement": [
{
"Effect": "Allow",
"Principal": {
"Service": "lambda.amazonaws.com"
},
"Action": "sts:AssumeRole"
}
]
}
Which of the following modifications to Account B's `S3WriteRole` trust policy will resolve this authorization error?
- AKeep the Service principal as lambda.amazonaws.com and add a Condition block matching the aws:PrincipalArn to arn:aws:iam::111111111111:role/LambdaExecutionRole.
- BUpdate the Action element in the trust policy to include both sts:AssumeRole and s3:PutObject, and set the Resource to the S3 bucket ARN.
- Change the Principal element in the trust policy to trust the AWS resource ARN: "AWS": "arn:aws:iam::111111111111:role/LambdaExecutionRole".Answer
- DHardcode the access keys of an IAM user in Account B who has write access to the S3 bucket directly into the Lambda function code, bypassing the STS call.