Remove harcoded password from cloudformation template without affecting a database - amazon-web-services

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.

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.

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).

Specifying an S3 bucket when deploying a cloudformation template

I'm trying to deploy a cloudformation template using a command that looks as follows:
aws cloudformation deploy \
--stack-name stackname \
--template-file folder/file.yaml \
--s3-bucket bucketname \
--s3-prefix prefix
The error that I receive is:
An error occurred (ValidationError) when calling the CreateChangeSet operation:
S3 error: The bucket you are attempting to access must be addressed using the specified endpoint. Please send all future requests to this endpoint.
For more information check
http://docs.aws.amazon.com/AmazonS3/latest/API/ErrorResponses.html
I have checked the link to try and understand what is being asked of me, but it seems to relate to directly using S3, and not using S3 via CloudFormation.
I can't determine a way to do what it is asking using the available parameters of aws cloudformation
The template file that defines a stack must be in an Amazon S3 bucket that is in the same region as the AWS CloudFormation stack being created.
aws cloudformation deploy --stack-name myteststack --template-file folder/file.yaml --s3-bucket bucketname --s3-prefix prefix --region us-east-1
You may replace the parameter and try this.
You need not to pass the region for s3 bucket nor endpoint is required. Yes, if the Bucket and Cloudformation are in a different region in such cases you may face an issue. But I'm sure it will be access denied issue, not something that you have mentioned here.

cloudformation deploy capability_auto_expand

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 ^

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.