Question

Difficulty: MediumAWS Serverless Application Model (SAM)

A developer is using AWS SAM to deploy a serverless application. The template file (`template.yaml`) contains the following definition:

yaml
AWSTemplateFormatVersion: '2010-09-09'

Resources:
ProcessDataFunction:
Type: AWS::Serverless::Function
Properties:
Handler: index.handler
Runtime: nodejs18.x
CodeUri: ./src
Events:
GetRequest:
Type: Api
Properties:
Path: /data
Method: get

When the developer attempts to deploy the application, the deployment fails with errors indicating unrecognized resource types and invalid code locations.

Which two actions must the developer take to resolve these issues and successfully deploy the application? (Select two.)

  1. Add the `Transform: AWS::Serverless-2016-10-31` declaration at the root level of the template.Answer
  2. Run the `sam deploy` command to package the local code, upload the zip archive to Amazon S3, and deploy the stack.Answer
  3. C
    Deploy the template directly using the `aws cloudformation deploy` command without packaging the local artifacts.
  4. D
    Add an IAM trust policy under the `Globals` section of the template to permit Amazon API Gateway to assume the Lambda function's role.
  5. E
    Configure the function's code to return a raw string directly to bypass API Gateway proxy payload validation requirements.

Answer

Add the `Transform: AWS::Serverless-2016-10-31` declaration at the root level of the template, and run the `sam deploy` command to package the local code, upload the zip archive to Amazon S3, and deploy the stack.
To successfully deploy the application, the developer must first add the `Transform: AWS::Serverless-2016-10-31` statement to the template. This enables the CloudFormation service to parse and translate SAM resources. Second, because the template references a local path for the function's code (`CodeUri: ./src`), the developer must package the code and upload it to Amazon S3. The `sam deploy` command automatically handles both the packaging of local artifacts to S3 and the deployment of the generated template.

Step-by-Step Solution

1
Analyze the validation errors in the CloudFormation deployment trace.
Identify that CloudFormation fails to recognize `AWS::Serverless::Function` and cannot resolve the local path `./src` for code execution.
This helps target the missing template-level processor definition and the untranslated local reference.
2
Add the required SAM transform statement to the template root.
The template now contains the `Transform: AWS::Serverless-2016-10-31` header, allowing the CloudFormation engine to translate SAM-specific resources into standard resources.
This is a mandatory declaration for any AWS SAM template.
3
Use the SAM CLI commands to upload local assets and deploy the resources.
Run `sam deploy`, which compiles, zips, and uploads the local folder to S3, replaces `CodeUri` with the S3 URI, and initiates the CloudFormation deployment.
CloudFormation does not natively support local directory uploads, so packaging via SAM is required.

Key Concept

AWS SAM template structure and deployment workflow using CLI tools
Rate this question