A software team is designing a serverless microservice using the AWS Serverless Application Model (SAM). The architecture requires an API Gateway HTTP API that triggers a backend AWS Lambda function. The function must securely fetch database credentials at runtime and also publish messages to an Amazon SQS queue.
Which two configuration steps must be implemented to ensure the deployment succeeds and the function operates correctly?
- Declare the 'Transform' header with the value 'AWS::Serverless-2016-10-31' at the root of the template file to instruct CloudFormation to process the SAM syntax.Answer
- Under the function's Properties block in the template, define the 'Policies' key referencing the 'SQSSendMessagePolicy' SAM policy template with the target queue name.Answer
- CDefine a custom IAM execution role for the function and modify its trust policy to specify the SQS service principal ('sqs.amazonaws.com') as the trusted entity.
- DStore the database password in AWS Systems Manager Parameter Store as a standard string parameter, and reference it directly in the environment variables block.
- EConfigure the Lambda function to return a plain text string payload, because API Gateway proxy integrations automatically format raw string return values into standard JSON responses.
Answer
The correct configurations are to declare the 'Transform' header with the value 'AWS::Serverless-2016-10-31' at the root of the template, and define the 'Policies' key referencing the 'SQSSendMessagePolicy' SAM policy template under the function's properties block.
Declaring the 'Transform' header with 'AWS::Serverless-2016-10-31' is mandatory for AWS SAM templates to convert serverless resource declarations into standard CloudFormation resources. Additionally, using the 'SQSSendMessagePolicy' template under the function's 'Policies' block is the standard, secure way in SAM to grant write permissions to an SQS queue without writing a full, custom IAM policy.
Step-by-Step Solution
Key Concept
AWS SAM templates require a Transform declaration at the root and support SAM policy templates to securely grant AWS resource permissions to serverless functions.
Estimated Time:2m 0s