A developer is writing an AWS Lambda function that programmatically launches an Amazon EC2 instance using the AWS SDK. The EC2 instance requires an IAM role to access an Amazon S3 bucket. The developer has created the EC2 IAM role `EC2AccessS3Role` and an associated instance profile.
The Lambda function runs under an execution role with the following identity-based policy:
{
"Version": "2012-10-17",
"Statement": [
{
"Effect": "Allow",
"Action": [
"ec2:RunInstances",
"ec2:DescribeInstances"
],
"Resource": "*"
}
]
}
When the Lambda function executes the code to launch the instance with the instance profile, the API call fails with a `Client.UnauthorizedOperation` error.
Which of the following actions will resolve this issue?
- AModify the trust policy of the `EC2AccessS3Role` to allow the Lambda service (`lambda.amazonaws.com`) to assume the role.
- Add the `iam:PassRole` permission to the Lambda function's execution role policy, specifying the ARN of the `EC2AccessS3Role` as the resource.Answer
- CModify the Lambda function's code to initialize the AWS SDK client using hardcoded AWS access keys of an IAM user that has administrative privileges.
- DModify the trust policy of the Lambda execution role to allow the `EC2AccessS3Role` to assume the Lambda role.