Question

Difficulty: MediumIAM Policies and Roles

A developer is creating an AWS Lambda function that processes files uploaded to an Amazon S3 bucket. The developer creates an IAM role named `S3ProcessRole` with the required S3 permission policies. However, when trying to assign the role to the Lambda function, the developer receives an error indicating that the role cannot be assumed by Lambda. The developer inspects the role's trust policy:

{
"Version": "2012-10-17",
"Statement": [
{
"Effect": "Allow",
"Principal": {
"AWS": "arn:aws:iam::987654321098:root"
},
"Action": "sts:AssumeRole"
}
]
}

Which modification to the trust policy is required to resolve this error?

  1. Update the Principal block in the trust policy to specify "Service": "lambda.amazonaws.com".Answer
  2. B
    Add the required s3:GetObject and s3:PutObject permissions to the Action block of the trust policy.
  3. C
    Change the Action in the trust policy from sts:AssumeRole to lambda:InvokeFunction.
  4. D
    Initialize the AWS SDK client inside the Lambda function code using hardcoded AWS access keys to bypass the role assignment.

Answer

Update the Principal block in the trust policy to specify the Lambda service principal.
The correct answer is to modify the Principal block to allow the AWS Lambda service principal (lambda.amazonaws.com) to assume the role. When Lambda runs a function, it must assume the execution role via the sts:AssumeRole action. For this to succeed, the role's trust policy must explicitly trust the Lambda service principal.

Step-by-Step Solution

1
Identify the cause of the failure: the trust policy limits assumption of the role to the root of AWS account 987654321098, preventing the AWS Lambda service from assuming it.
Discovered that the Principal specifies the account root rather than the Lambda service principal.
Before a service can assume an IAM role, the trust policy must explicitly permit that specific service principal.
2
Locate the Principal block in the trust policy JSON.
Isolated the 'Principal': { 'AWS': 'arn:aws:iam::987654321098:root' } block.
This is the segment governing who is trusted to assume the role.
3
Change the Principal from the AWS account root to the Lambda service principal, lambda.amazonaws.com, and keep the Action as sts:AssumeRole.
The Lambda service principal is now trusted, allowing the function to execute with the role's permissions.
This establishes the necessary trust relationship for the AWS Lambda service.

Key Concept

IAM Role Trust Policies vs. Permissions Policies
Estimated Time:1m 30s
Rate this question