A developer is deploying a serverless application using a local AWS Serverless Application Model (SAM) template file named `template.yaml`. The template contains the following definition:
yaml
AWSTemplateFormatVersion: '2010-09-09'
Transform: AWS::Serverless-2016-10-31
Resources:
GetProductFunction:
Type: AWS::Serverless::Function
Properties:
Handler: index.handler
Runtime: nodejs20.x
CodeUri: ./src
Events:
GetProduct:
Type: Api
Properties:
Path: /products/{id}
Method: get
The developer attempts to deploy the application directly by executing the following AWS CLI command:
`aws cloudformation deploy --template-file template.yaml --stack-name product-service-dev --capabilities CAPABILITY_IAM`
However, the command fails, indicating that the `CodeUri` property of the `AWS::Serverless::Function` resource must point to an Amazon S3 location.
Which of the following statements identifies the root cause of this error and the correct action to resolve it?
- AThe template has the `Transform: AWS::Serverless-2016-10-31` declaration defined at the root level, but this declaration must be moved under the `Metadata` section of the template so that the CloudFormation service can parse and auto-upload local paths.
- CloudFormation cannot natively resolve local directory paths like `./src`. The developer must use `sam deploy` (or execute `aws cloudformation package` followed by `aws cloudformation deploy` using the generated packaged template) to zip and upload the local directory to Amazon S3, replacing the local path with an S3 URI.Answer
- CThe execution role associated with the CloudFormation stack deployment is missing a trust policy allowing the `apigateway.amazonaws.com` service principal to assume the role, preventing CloudFormation from reading from the local path.
- DThe API Gateway integration is configured as a proxy integration, which requires the backend Lambda function to return a structured JSON response containing headers, statusCode, and body to authorize local file access.