get cloudformation parameters from .txt file/s3 bucket

2.6k views Asked by At

I want to pass input parameter to cloudformation properties from text file or save the text file in s3 bucket and point the s3 URL in CF properties.

Please let me know if this is possible? If yes, how to do?

2

There are 2 answers

0
mfisherca On

There isn't a way if you're using the AWS management console to create the CloudFormation stack, but you can if you use the AWS CLI. Save the parameters into a text file (e.g. parameters.txt) in one of the following formats:

Shorthand:

ParameterKey=string,ParameterValue=string,UsePreviousValue=boolean ...

JSON:

[
 {
   "ParameterKey": "string",
   "ParameterValue": "string",
   "UsePreviousValue": true|false
 }
 ...
]

Then use the AWS CLI command cloudformation create-stack, e.g.:

aws cloudformation create-stack --stack-name <YourStackName> \
  --template-body file://<YourTemplateFileName.ext> \
  --parameters file://parameters.txt

Unfortunately it doesn't seem --parameters can reference an S3 bucket directly, only a local file or inline parameters.

0
Sunil Shakya On

See this blog parameter you pass using s3 url:

https://aws.amazon.com/blogs/devops/passing-parameters-to-cloudformation-stacks-with-the-aws-cli-and-powershell/

also try this:

aws cloudformation create-stack --stack-name <YourStackName> \
  --template-body file://<YourTemplateFileName.ext> \
  --parameters $(aws s3 cp S3:/yourbucketname\parameters.txt - )