A developer is creating a serverless application using AWS SAM. The application contains an Amazon SQS queue and an AWS::Serverless::Function that needs to process messages from the queue. The function must have the minimum necessary permissions to poll messages from the SQS queue and delete them after processing. Which two configurations in the AWS SAM template are required to set up this event source and its permissions?
- Configure an event source under the function's Events property with the Type set to SQS and the Queue property referencing the SQS queue ARN.Cevap
- Include the SQSPollerPolicy policy template under the function's Policies property, specifying the SQS queue name.Cevap
- CConfigure an IAM trust policy on the SQS queue that allows the lambda.amazonaws.com service principal to assume the queue's execution role.
- DRemove the Transform: AWS::Serverless-2016-10-31 declaration from the template since standard AWS CloudFormation natively interprets the AWS::Serverless::Function resource type.
- ESet the Lambda function's Timeout to be greater than the SQS queue's visibility timeout to ensure the function has enough time to process and delete the messages.
Cevap
The correct configurations are: (1) Configure an event source under the function's Events property with the Type set to SQS and the Queue property referencing the SQS queue ARN; (2) Include the SQSPollerPolicy policy template under the function's Policies property, specifying the SQS queue's name.
To integrate an SQS queue with an AWS SAM Lambda function, you need two primary configurations: defining the event source and granting the necessary permissions. Specifying the SQS event source under the Events property ensures the AWS Lambda service invokes the function upon message arrival. Referencing the SQSPollerPolicy template under the Policies property is the standard, secure way to assign the Lambda execution role the exact permissions required to pull and process the queue messages.
Adım Adım Çözüm
Anahtar Kavram
AWS SAM Event Sources and Policy Templates