cloudformation deploy capability_auto_expand - amazon-web-services

I'm attempting to create a script to automate the deployment/updating of my SAM stack. I'm using batch to do this. Right now I have:
call aws cloudformation deploy --template-file "serverless.yml" ^
--stack-name %1 ^
--capabilities CAPABILITY_AUTO_EXPAND CAPABILITY_IAM^
--parameter-overrides ^
StageName=%1^
{some other parameters}
--role-arn {my role arn}
where %1 is the batch argument with the stack/stage name.
When i attempt to run this, I get the error in the cloudformation console that I need CAPABILITY_AUTO_EXPAND to update some of my stacks. Looking at the documentation, it looks like aws cloudformation deploy does not support this capability? And aws cloudformation update-stack does not accept a filename for a template.
Any suggestions on how to do this?

probably you should use clean formatting
aws cloudformation deploy \
--region "${region}" \
--template-file output.yaml \
--stack-name "${stackName}" \
--capabilities CAPABILITY_IAM CAPABILITY_AUTO_EXPAND \
--parameter-overrides ;

See answer provided by similar question and the answer relevant to the cli commands.
Sorry would have used comment instead of answer but don't yet have privileges.

After switching to sam deploy I figured out that it was an issue with the spaces before and after my line breaks.
Specifically I think I had too many spaces in
--stack-name %1{space}{space}{space}^{space}
then no space after the capabilities line. Cleaned up the spacing throughout the command and it works now
I believe that the biggest issue was the space after the ^

Related

How do I set an AWS Stack name (for a Lambda Layer) in a SAM Template?

This page describes how to set a stack name in some AWS console GUI: https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/cfn-using-console-create-stack-parameters.html
How do I set these values in the SAM Template .yml files?
I'm specifically doing this on a Stack that is only a Lambda Layer if that matters.
I can see that there is some way to do this via CLI as described here:
https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/using-cfn-cli-creating-stack.html
aws cloudformation create-stack --stack-name myteststack --template-url "ssm-doc://arn:aws:ssm:us-east-1:123456789012:document/documentName"
Is it even possible to set the name in the template?
Unfortunately, it seems like stack name is NOT part of the SAM templates. This is done via the command arguments to deploy the stack.
From the same link: https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/using-cfn-cli-creating-stack.html
The following example creates the myteststack stack in an Amazon S3 bucket:
PROMPT> aws cloudformation create-stack \
--stack-name myteststack \
--template-body file:///home/testuser/mytemplate.json \
--parameters ParameterKey=Parm1,ParameterValue=test1 ParameterKey=Parm2,ParameterValue=test2
So when creating the stack, the --stack-name argument is how this is set.
The reason I was confused is because I didn't realize where that command was being issued.

Remove harcoded password from cloudformation template without affecting a database

I'm trying to fix an error I made a time ago.
When I deployed or created my stack, I included a parameters file (json) with the password that was used to create a database in AWS RDS instead of using Parameter Store. Yes. Stupid idea!
aws cloudformation create-stack --stack-name my-stack \
--template-body file://my-stack.yml \
--parameters file://my-stack.json \
Anyway, I'm trying to amend that. What would be the best way to do it without deleting or affecting the database? I don't want to lose data or have to delete and create the database in AWS RDS. And, I want to be sure that next deployments or stack updates will not include the password.
aws cloudformation update-stack --stack-name my-stack \
--template-body file://my-stack.yml \
--parameters file://my-stack.json \
Any help or advice would be appreciated.

Difference between --parameter-overrides and --tags

I am having a hard time understanding the difference between --parameter-overrides and --tags when deploying an AWS stack using CloudFormation.
I tried to read through the documentation but I still do not understand, I seem to get exactly the same behaviour when I use the cli to deploy my stack with the usage of one or the other flag, such as
aws --profile $PROFILE cloudformation deploy
--stack-name ${STACK_NAME}
--template-file $TEMPLATE_FILE
--parameter-overrides
ApplicationName=$APP_NAME
--no-fail-on-empty-changeset
--tags
ApplicationName=$APP_NAME
When and why would I use the tags? Any help?
--tags set arbitrary Tags on the Stack. Tags are key-value metadata for labelling and categorizing AWS resources. Tags are optional. They do not affect how CloudFormation deploys the stack.
--parameter-overrides inject parameter values into the template. Optional if you are happy with the template's parameter defaults (for new deploys) or currently deployed values (for updates).

Cloudformation append to stack

I have an AWS stack with lambda and api gateway resources. There are about 250 resources and cloudformation only allows uploading 200 at a time so I split it into 2 templates. However when I run the deploy commands for each stack like so
aws cloudformation deploy --template-file template.yml --stack-name my-stack --region us-east-1 --capabilities CAPABILITY_IAM
aws cloudformation deploy --template-file template2.yml --stack-name my-stack --region us-east-1 --capabilities CAPABILITY_IAM
the second command deletes what the first command deployed to my-stack. I would like to append the resources in template2.yml to my-stack and keep what was deployed from template.yml. Is there a way to do that? I want the resources in both templates to use the same api gateway endpoint.
They are technically 2 stacks, but you only gave 1 stack name. So the later command will overwrite the deployed my-stack based on template.yml.
Change your 2nd command to use a different stack name like my-stack2
You could deploy this specifications into two different stacks (diferent stack names), besides you could reference the api gateway specification from the first stack into the second stack, this is one way to reference lambda functions in same api gateway.

CAPABILITY_NAMED_IAM using cloud9

I am trying to do all my dev work using cloud9 template for serverless apps
It complains that i don't have CAPABILITY_NAMED_IAM due to the fact that I am creating a role. How do I edit cloud9 deploy defaults to include CAPABILITY_NAMED_IAM?
If you started your Cloud9 with Code star, you can modify the pipeline to enable capabilities to CAPABILITY_NAMED_IAM in the AWS management console.
You need to edit the GenerateChangeSet section in the deploy step.
Otherwhise you should look into your create/update stack to add the --capabilities CAPABILITY_NAMED_IAM :
cloudformation create-stack --stack-name my-stack --template-url dummy-template.yaml --role-arn ... --tags ... --capabilities CAPABILITY_NAMED_IAM
https://docs.aws.amazon.com/AWSCloudFormation/latest/APIReference/API_CreateStack.html
https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/using-iam-template.html#using-iam-capabilities