Soru

Zorluk: OrtaIAM Policies and Roles

A developer is deploying an AWS Lambda function that reads incoming user data from an Amazon Kinesis data stream. The developer creates an IAM role with a permissions policy allowing the necessary Kinesis read actions. However, the Lambda function fails to retrieve data, and the logs indicate that the Lambda service is unauthorized to assume the configured execution role.

The trust policy attached to the IAM role is shown below:

{
"Version": "2012-10-17",
"Statement": [
{
"Effect": "Allow",
"Principal": {
"Service": "kinesis.amazonaws.com"
},
"Action": "sts:AssumeRole"
}
]
}

How should the developer resolve this issue to allow the Lambda function to execute and read from the stream?

  1. A
    Add the kinesis:DescribeStream and kinesis:GetRecords permissions directly into the Action array of the trust policy.
  2. B
    Initialize the AWS SDK client inside the Lambda function code by passing the AWS access key and secret access key associated with the IAM role.
  3. Change the service principal in the trust policy to "lambda.amazonaws.com" to allow the Lambda service to assume the execution role.Cevap
  4. D
    Change the Action in the trust policy from sts:AssumeRole to kinesis:AssumeRole to align with the service principal configuration.

Cevap

Change the service principal in the trust policy to "lambda.amazonaws.com" to allow the Lambda service to assume the execution role.
To resolve the assumption failure, the trust policy of the execution role must specify lambda.amazonaws.com as the trusted service principal. This grants the AWS Lambda service the permission to assume the role and perform actions on behalf of the function.

Adım Adım Çözüm

1
Analyze the error logs and trust policy of the execution role.
The log states the Lambda service is unauthorized to assume the role, and the trust policy lists 'kinesis.amazonaws.com' as the service principal.
Understanding why the assumption failed requires verifying the trust relationship configuration.
2
Identify the service principal that needs to assume the role.
The Lambda service itself ('lambda.amazonaws.com') is responsible for assuming the execution role and running the function code.
The trust policy must grant the service running the resource the permission to call 'sts:AssumeRole'.
3
Update the trust policy's principal block.
Change 'kinesis.amazonaws.com' to 'lambda.amazonaws.com'.
This grants the Lambda service the permission to assume the execution role natively.

Anahtar Kavram

IAM trust policies define which entities (accounts, users, or AWS services) are trusted to assume an IAM role, while IAM permissions policies define what actions the assumed role can perform.
Bu soruyu puanla