Question

Difficulty: EasyIAM Policies and Roles

A developer is creating an IAM role for an AWS Lambda function that needs to write logs to an Amazon S3 bucket named "my-app-logs-bucket". The developer has written the following permissions policy:

{
"Version": "2012-10-17",
"Statement": [
{
"Effect": "Allow",
"Action": "s3:PutObject",
"Resource": "arn:aws:s3:::my-app-logs-bucket/*"
}
]
}

Which two configuration steps must the developer perform to ensure the Lambda function has the necessary permissions to write to the S3 bucket?

  1. Configure the trust policy of the IAM role to allow the lambda.amazonaws.com service principal to perform the sts:AssumeRole action.Answer
  2. Attach the S3 permissions policy to the IAM role that is associated with the Lambda function.Answer
  3. C
    Configure the trust policy of the IAM role to allow the s3.amazonaws.com service principal to perform the sts:AssumeRole action.
  4. D
    Embed the IAM user access key and secret access key directly in the Lambda function code to authorize the S3 client.
  5. E
    Define the s3:PutObject action inside the principal block of the trust policy document.

Answer

Configure the trust policy of the IAM role to allow the lambda.amazonaws.com service principal to perform the sts:AssumeRole action, and attach the permissions policy to the IAM role associated with the Lambda function.
To allow an AWS Lambda function to access S3 resources using an IAM role, two components are required: a permissions policy attached to the role that allows the s3:PutObject action, and a trust policy configured on the role that allows the Lambda service (lambda.amazonaws.com) to assume the role (sts:AssumeRole).

Step-by-Step Solution

1
Identify the entity assuming the role.
The Lambda service principal (lambda.amazonaws.com) needs to run the function and obtain temporary credentials.
This determines the trust policy configuration allowing sts:AssumeRole.
2
Identify where permissions are attached.
The permissions policy allowing s3:PutObject must be attached to the execution role.
This grants the assumed role the authority to write to the S3 bucket.

Key Concept

IAM execution roles require both a trust policy allowing the service to assume the role and permissions policies granting access to destination resources.
Rate this question