Soru

Zorluk: OrtaAWS Serverless Application Model (SAM)

A developer is deploying a serverless application using AWS SAM. The template file (`template.yaml`) defines several `AWS::Serverless::Function` resources with the `CodeUri` property pointing to local directories (e.g., `./src`). The developer attempts to deploy the template directly using the command `aws cloudformation deploy --template-file template.yaml --stack-name my-stack`. The deployment fails with errors indicating that the template format is invalid because the `AWS::Serverless` resources are not recognized, and the local paths for `CodeUri` cannot be resolved. Which TWO actions must the developer take to resolve these issues and successfully deploy the application?

  1. Add the `Transform: AWS::Serverless-2016-10-31` declaration at the root level of the template file.Cevap
  2. Run the `sam package` command to upload the local artifacts to an Amazon S3 bucket and generate a new template file with S3 URIs.Cevap
  3. C
    Store the function code in AWS Systems Manager Parameter Store and reference the parameter key in the `CodeUri` property.
  4. D
    Modify the trust policy of the Lambda execution role to allow the `cloudformation.amazonaws.com` service principal to assume the role.
  5. E
    Increase the default Lambda function timeout in the template to 30 seconds to allow the CloudFormation deployment to complete.

Cevap

To deploy a SAM application successfully, the developer must add the `Transform: AWS::Serverless-2016-10-31` declaration at the root level of the template file to enable SAM syntax translation, and run the `sam package` command to upload local assets to Amazon S3 and produce a packaged template referencing those S3 locations.
The correct options involve adding the `Transform: AWS::Serverless-2016-10-31` declaration to enable the CloudFormation SAM parser, and running the `sam package` command to process local paths and upload code artifacts to Amazon S3. These two steps resolve the validation errors and local file path reference limitations in CloudFormation.

Adım Adım Çözüm

1
Add the required serverless transform header to the SAM template.
The template now includes `Transform: AWS::Serverless-2016-10-31` at the root level.
Without this declaration, AWS CloudFormation does not recognize SAM resource types like `AWS::Serverless::Function` and fails during parsing.
2
Run the `sam package` command specifying an Amazon S3 bucket for code storage.
The local artifacts are zipped and uploaded to the specified S3 bucket, and a new template file is generated where the `CodeUri` properties point to the S3 objects.
CloudFormation cannot upload local directory contents directly from the deployment command; packaging resolves local paths to S3 URIs.
3
Deploy the application using the packaged template file.
The stack is created or updated successfully in AWS CloudFormation.
The packaged template contains standard S3 locations and valid SAM syntax that CloudFormation can translate and execute.

Anahtar Kavram

AWS SAM templates must define the Transform header to be processed, and local files must be packaged and uploaded to Amazon S3 before deploying via CloudFormation.
Bu soruyu puanla