Soru

Zorluk: OrtaAWS Serverless Application Model (SAM)

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?

  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.Cevap
  2. Include the SQSPollerPolicy policy template under the function's Policies property, specifying the SQS queue name.Cevap
  3. C
    Configure an IAM trust policy on the SQS queue that allows the lambda.amazonaws.com service principal to assume the queue's execution role.
  4. D
    Remove the Transform: AWS::Serverless-2016-10-31 declaration from the template since standard AWS CloudFormation natively interprets the AWS::Serverless::Function resource type.
  5. E
    Set 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

1
Define the event trigger mapping.
Create an event mapping of type SQS pointing to the queue's ARN under the function's Events property.
This establishes the relationship that enables AWS Lambda to poll the SQS queue automatically.
2
Configure the security execution permissions using SAM policy templates.
Add SQSPollerPolicy under the function's Policies property.
This automatically creates the minimum required IAM permissions for the Lambda function to invoke SQS operations (ReceiveMessage, DeleteMessage, GetQueueAttributes) on the specified queue.

Anahtar Kavram

AWS SAM Event Sources and Policy Templates
Bu soruyu puanla