Question

Difficulty: EasyAWS Serverless Application Model (SAM)

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?

  1. Declare a Globals section at the root level of the template with a Function property containing Timeout: 15.Answer
  2. B
    Omit the Transform header from the template and define a Globals section containing the Timeout property directly under the Resources block.
  3. C
    Implement an initialization script within the Lambda handler code that dynamically adjusts the execution context timeout during a cold start.
  4. D
    Specify 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

1
Identify the AWS SAM feature used to define common configurations across resources.
The Globals section of an AWS SAM template allows developers to define common configuration settings for supported resources like Functions, APIs, and SimpleTables.
Using Globals reduces template redundancy and enforces consistent configurations.
2
Determine the correct structure for the Globals section to define Lambda timeouts.
The Globals section must be defined at the root level (same level as Transform and Resources) and contain a Function block with properties like Timeout.
This syntax tells the SAM translator to inject these properties into all AWS::Serverless::Function resources during deployment.

Key Concept

AWS SAM Globals Section
Rate this question