Question

Difficulty: EasyAWS Serverless Application Model (SAM)

A developer is writing an AWS Serverless Application Model (SAM) template to deploy a Lambda function that handles API requests. The developer wants to apply a default timeout of 10 seconds to all functions and ensure that the template is parsed correctly by AWS CloudFormation as a SAM template.

yaml
AWSTemplateFormatVersion: '2010-09-09'
# [Configuration 1]

Globals:
# [Configuration 2]

Resources:
ProcessRequestFunction:
Type: AWS::Serverless::Function
Properties:
CodeUri: src/
Handler: index.handler
Runtime: nodejs18.x

Which two configuration steps must the developer take to complete the template?

  1. Declare `Transform: AWS::Serverless-2016-10-31` at the root level of the templateAnswer
  2. Define `Function:` followed by `Timeout: 10` inside the `Globals` sectionAnswer
  3. C
    Declare `Transform: AWS::CloudFormation::Serverless` at the root level of the template
  4. D
    Define `Parameters:` followed by `DefaultTimeout: 10` inside the `Globals` section
  5. E
    Define `Role:` followed by `AssumeRolePolicyDocument: Timeout: 10` inside the `Globals` section

Answer

The developer must declare the correct SAM transform at the root level of the template and specify the function timeout under the Globals section.
To complete the AWS SAM template, the template must include the correct `Transform` header at the root level to instruct CloudFormation to process it using the SAM translator, and the `Globals` section must define the `Timeout` under `Function` to apply it to all functions in the template.

Step-by-Step Solution

1
Identify the required header to enable AWS SAM parsing in CloudFormation.
The root of the template must include the `Transform: AWS::Serverless-2016-10-31` declaration.
Without the correct Transform header, AWS CloudFormation will fail to recognize SAM-specific resources such as AWS::Serverless::Function.
2
Configure the global default properties for all Lambda functions defined in the template.
Under the `Globals` section, add a `Function` block containing `Timeout: 10`.
The `Globals` section allows properties common to multiple resources, like function timeouts, to be defined once and applied to all instances of that resource type.

Key Concept

AWS Serverless Application Model (SAM) templates require a specific Transform header to be processed by CloudFormation, and support a Globals section to define shared resource properties.
Rate this question