An engineering team is developing a serverless application using the AWS Serverless Application Model (SAM). The team wants to define a default timeout of 15 seconds that automatically applies to all Lambda functions declared in the template, rather than specifying the timeout property individually for each function resource. Which of the following approaches should the team use to meet this requirement?
- Declare a Globals section at the root level of the template with a Function property containing Timeout: 15.Answer
- BOmit the Transform header from the template and define a Globals section containing the Timeout property directly under the Resources block.
- CImplement an initialization script within the Lambda handler code that dynamically adjusts the execution context timeout during a cold start.
- DSpecify the timeout value inside the Statement block of the IAM trust policy associated with the Lambda execution role.
Answer
Declare a Globals section at the root level of the template with a Function property containing Timeout: 15.
Declaring the configuration under the Globals section at the root level of the template using the Function property allows the AWS SAM translator to apply that property (Timeout: 15) to all serverless functions in the template.
Step-by-Step Solution
Key Concept
AWS SAM Globals Section