Aws-cli: Syntax for template parameters with cloudformation create-stack is inscruitable

Created on 19 Feb 2013  路  13Comments  路  Source: aws/aws-cli

Given a simple template:

{
    "AWSTemplateFormatVersion":"2010-09-09",
    "Description":"Example template",
    "Parameters":{
        "ExampleParameter":{
            "Type":"Number"
        }
    },
    "Resources":{
        "ExampleVolume":{ 
            "Type":"AWS::EC2::Volume",
            "Properties":{
                "AvailabilityZone":"us-east-1a",
                "Size":"10",
                "Tags": [ 
                    { "FirstTag" : { "Ref" : "ExampleParameter" } }
                ]
    }
}

then the syntax for providing a value for ExampleParameter on the command line is ... well, I can't work it out.

I'm using the following:

aws cloudformation create-stack --stack-name test-stack --template-body "<template>" --parameters file:parameters-file

and the contents of parameters-file as being any of:

["ExampleParameter":1234]
["ExampleParameter":"1234"]
{ ["ExampleParameter":"1234"] }
[{"Parameter":{"ParameterKey":"ExampleParameter","ParameterValue":"1234"}}]
{ "Parameters": [ "ExampleParameter":{"ParameterKey":"ExampleParameter","ParameterValue":"1234"}]}

and a bunch of other, more wacky manglings, but I just cannot get it to work.

Edit: many of the bad inputs get response from botocore like:

Expecting , delimiter: line 1 column 19 (char 19)

and those inputs that do get parsed get a response from AWS like:

{
"ErrorResponse": {
    "RequestId": "d0fc4af5-7a55-11e2-afd2-23222bc4e432", 
    "Error": {
        "Message": "Template requires parameter: ExampleParameter", 
        "Code": "ValidationError", 
        "Type": "Sender"
    }
}
}

Some examples or advice would be welcome ...

Most helpful comment

hi All,
Any improvement here since 2013? Any way to use '--parameters file:///...' instead of list of parameters?
Thank you.

All 13 comments

Further information: running with --debug shows me that even though parameters are getting parsed in the forms which work, none of them are being sent in the POST.

(I also notice that I left out two closing braces in the template ... sorry for the transcription error)

snippets from --debug:

...
2013-02-19 16:41:30,558 - botocore.parameters - DEBUG - name: Parameters
2013-02-19 16:41:30,558 - botocore.parameters - DEBUG - label: 
...
send: 'POST / HTTP/1.1\r\nHost: cloudformation.us-east-1.amazonaws.com\r\nAccept-Encoding: identity\r\nContent-Length: 529\r\nContent-Type: application/x-www-form-urlencoded\r\nAuthorization: AWS4-HMAC-SHA256 Credential=xxxxxxxxxxxxx/20130219/us-east-1/cloudformation/aws4_request, SignedHeaders=host;user-agent;x-amz-date, Signature=xxxxxxxx\r\nX-Amz-Date: 20130219T054130Z\r\nUser-Agent: aws-cli/0.5.3 Python/2.7.3 Linux/3.7.6-102.fc17.x86_64\r\n\r\nStackName=example&Action=CreateStack&Version=2010-05-15&TemplateBody=%7B%22AWSTemplateFormatVersion%22%3A%222010-09-09%22%2C%22Description%22%3A%22Example+template%22%2C%22Parameters%22%3A%7B%22ExampleParameter%22%3A%7B%22Type%22%3A%22Number%22%7D%7D%2C%22Resources%22%3A%7B%22ExampleVolume%22%3A%7B%22Properties%22%3A%7B%22AvailabilityZone%22%3A%22us-east-1a%22%2C%22Size%22%3A%2210%22%2C%22Tags%22%3A%5B%7B%22FirstTag%22%3A%7B%22Ref%22%3A%22ExampleParameter%22%7D%7D%5D%7D%2C%22Type%22%3A%22AWS%3A%3AEC2%3A%3AVolume%22%7D%7D%7D'
reply: 'HTTP/1.1 400 Bad Request\r\n'

Okay, I figured it out ... I hope this issue (and comment) helps others.

The correct syntax is:

[{"parameter_key":"ExampleParameter","parameter_value":"1234"}]

If you need to supply multiple parameters, the syntax is:

[ {"parameter_key":"Param1","parameter_value":"1234"},{"parameter_key":"Param2","parameter_value":"1234"} ]

This did my head in for a while.

Thanks for your diligence 8^) We acknowledge that the actual format of complex parameters is currently difficult to decipher. We are working on a couple of ways to improve this. I'll update this ticket when this work has been completed.

What's the correct syntax for passing the parameters on the command line rather than as a 'file:'?

Hi Tom,

The syntax for command-line use is the same; using a file: prefix just makes it pull the contents from a file instead of from stdin. Of course, this may present some interesting challenges with quoting, shell metacharacters, and so on but for the most part it's straightforward.

Example:

$ aws cloudformation create-stack --stack-name my-test-stack \
    --template-body file:my-template.json \
    --parameters '[{"parameter_key":"KeyName","parameter_value":"my-ssh-keyname"}]'

Thanks for that, I was trying to wrap the JSON list in single quoted braces. Didn't think to just single quote the list.

I'm having more fun now!

What is the new syntax these days ?
I just tried the syntax described by @nonspecialist above but it seems it does not work anymore

I am using

$ aws --version
aws-cli/0.16.0 Python/2.7.2 Darwin/12.4.0
$ pip list | grep boto
boto (2.11.0)
botocore (0.16.0)

I tested this format

[{"parameter_key":"name", "parameter_value":"test"}]

And received

Invalid value ('parameter_key') for param element of list:Parameters of type list

I just run into the same issue, now the format seems to be [{"ParameterKey":"name", "ParameterValue":"test"}]

For the single quote I believe that with a single note on the official documentation or the help command will do: "Note: for the json sintax single quote the json string" it would save lots of headaches

Why is it necessary to specify a hash of ParameterKey and ParameterValue instead of creating the hash directly?
{ "name": "value", "instance": "i-03fa8d" }
is a lot more readable than
[ {"ParameterKey": "name", "ParameterValue": "test"}, {"ParameterKey": "instance", "ParameterValue": "i-03fa8d"} ]

I see it's possible to have some abbreviation, like:

--parameters ParameterKey=Vpc,ParameterValue=vpc-1f616a7d ParameterKey=SubnetA,ParameterValue=subnet-44e1e926 ParameterKey=SubnetB,ParameterValue=subnet-36d8f342

but that's still pretty ugly compared to

--parameters Vpc=vpc-1f616a7d, SubnetA=subnet-44e1e926, SubnetB=subnet-36d8f342

and it's especially annoying, since u have to specify these again when u r doing an aws cloudformation update-stack ...

See #484. This is being actively worked and we hope to have an improved UI available for map-like values in the future.

hi All,
Any improvement here since 2013? Any way to use '--parameters file:///...' instead of list of parameters?
Thank you.

Any update on the above request to use '--parameters file:///...' instead of list of parameters ?

Thanks!

Was this page helpful?
0 / 5 - 0 ratings