Posted by on January 17, 2019

If you’re deploying AWS resources using Cloud Formation from the Command Line Interface (CLI), as many of us do in our code pipelines, then you’ll know the value of having a parameter file. Infrastructure as Code works better if you’re sending a consistent set of parameters, and, better yet, if your source code control tool is keeping track of who changed the parameters, when, and why.

Which can make testing a bit of a pain. We need to test our Cloud Formation templates before we submit a pull request and put them into a shared test environment. In that debugging process every once in a while I just run things in the console. When a console deploy works there is a working template, but no parameter file.

You can create a parameter file for any deployed stack by running the command:

aws cloudformation describe-stacks --stack-name your-stack-name

From the resulting output just copy the block after the key "Parameters":, including the square brackets but not the "Parameters": , and use it as your json parameters file. The resulting file should look like this:

[
    {
        "ParameterKey": "myParameter",
        "ParameterValue": "1"
    }
]

Then just use a file://URI with your CLI stack commands, like this:

aws cloudformation create-stack \
    --stack-name CodePipeline-Stack \
    --template-body file://codepipeline.cfn.yml \
    --parameters file://codepipeline.params.json \
    --capabilities CAPABILITY_NAMED_IAM
Posted in: Quick, Technical

Comments

Be the first to comment.

Leave a Reply