Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Update cloudformation stack from aws cli with SAM transform

When attempting to update a cloudformation stack in the aws cli:

aws --profile dev cloudformation update-stack --stack-name mystackname --template-body file://events-list.yaml

I get the following error

An error occurred (ValidationError) when calling the UpdateStack operation: UpdateStack cannot be used with templates containing Transforms.

Because I am using the AWS Serverless transform for lambda function deployments

Transform: 'AWS::Serverless-2016-10-31'

Is there a CLI way to execute this stack update or am I going to have to work on my APM in the GUI.

like image 849
Eric Nord Avatar asked Dec 21 '16 18:12

Eric Nord


2 Answers

You can use deploy instead of update-stack:

aws cloudformation deploy \
   --template-file serverless-output.yaml \
   --stack-name new-stack-name \
   --capabilities CAPABILITY_IAM

This command is necessary because Transforms need to be applied using change sets, which the deploy command automates for you. Refer to Working with Stacks that Contain Transforms for further discussion:

To create or update a stack with transforms, you must create a change set, and then execute it. A change set describes the actions AWS CloudFormation will take based on the processed template. During processing, AWS CloudFormation translates AWS SAM syntax into syntax that is defined by the transform. Processing can add multiples resources that you might not be aware of. For example, the specialized AWS::Serverless::Function resource adds an AWS Identity and Access Management (IAM) execution role and a Lambda function.

To ensure that you're aware of all of the changes introduced by transforms, AWS CloudFormation requires you to use change sets. [...]

If you use the AWS CLI, you can use the package and deploy commands to reduce the number of steps for launching stacks with transforms.

like image 190
wjordan Avatar answered Oct 23 '22 01:10

wjordan


Try with deploy instead of update-stack

aws cloudformation deploy \ --template-file serverless-output.yaml \ --stack-name new-stack-name \ --capabilities CAPABILITY_IAM

like image 43
Vibha Kant Avatar answered Oct 23 '22 02:10

Vibha Kant