A developer is deploying a serverless application using the AWS Serverless Application Model (SAM). The template defines an AWS::Serverless::Function resource that needs to read and write items in an Amazon DynamoDB table defined in the same template. During initial testing, the function fails to access the table due to missing permissions. The developer wants to resolve this issue by applying the principle of least privilege using the most operationally efficient method that native AWS SAM features support. Which configuration should the developer add to the template to resolve the permission issue?
- Add the Policies property to the AWS::Serverless::Function resource and reference the DynamoDBCrudPolicy policy template, passing the name of the DynamoDB table as a parameter.Cevap
- BAdd an AssumeRolePolicyDocument property to the function's properties that grants dynamodb:PutItem and dynamodb:GetItem permissions, listing the DynamoDB service principal dynamodb.amazonaws.com as the trusted entity.
- CCreate a separate standard AWS CloudFormation AWS::IAM::Role resource with the required DynamoDB permissions and attach it to the function, and remove the Transform: AWS::Serverless-2016-10-31 line from the top of the template to avoid resource parsing conflicts.
- DStore the required IAM policy JSON statement in AWS Systems Manager Parameter Store as a SecureString parameter, and use a dynamic reference in the function's Role property to fetch and apply the policy at runtime.
Cevap
Add the Policies property to the AWS::Serverless::Function resource and reference the DynamoDBCrudPolicy policy template, passing the name of the DynamoDB table as a parameter.
The correct answer provides the most secure and operationally efficient configuration. Specifying the DynamoDBCrudPolicy policy template under the Policies property of the AWS::Serverless::Function resource allows SAM to generate a scoped IAM policy for the function that only permits read/write actions on the designated DynamoDB table.
Adım Adım Çözüm
Anahtar Kavram
AWS SAM Policy Templates
Tahmini Süre:1m 30s