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.)
- Add the `Transform: AWS::Serverless-2016-10-31` declaration at the root level of the template.Answer
- Run the `sam deploy` command to package the local code, upload the zip archive to Amazon S3, and deploy the stack.Answer
- CDeploy the template directly using the `aws cloudformation deploy` command without packaging the local artifacts.
- DAdd an IAM trust policy under the `Globals` section of the template to permit Amazon API Gateway to assume the Lambda function's role.
- EConfigure 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
Key Concept
AWS SAM template structure and deployment workflow using CLI tools