Question:
For example, I have this CF template that ask for these parameters
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 |
----- cftemplate.yaml ----- ... Parameters: **Subnet: Description: Subnet for the Instance Type: 'AWS::EC2::Subnet::Id' SecurityGroups: Description: Security Group for Instance Type: 'List ... Resources: EC2Instance: Type: AWS::EC2::Instance Properties: ... **SubnetId: !Ref Subnet SecurityGroupIds: !Ref SecurityGroups** ... ----- cftemplate.yaml ----- |
For me to deploy the stack, I use this command:
1 2 |
aws cloudformation create-stack --stack-name StackName --template-body file://cftemplate.yaml --parameters file://params.json |
Where params.json contains:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 |
----- params.json ----- [ { "ParameterKey":"Subnet", "ParameterValue":"subnet-11111111" }, { "ParameterKey":"SecurityGroups", "ParameterValue":"sg-111111111", "ParameterValue":"sg-222222222" } ] ----- params.json ----- |
Now, my goal is to eliminate the use of .json file. Does anyone know the shorthand syntax of the command that should achieve the same effect as above command? Can’t seem to find this on the documentations online. Thanks in advance!
Answer:
The command line equivalent would be (little re-formatted for clarify):
1 2 3 4 5 |
aws cloudformation create-stack \ --stack-name StackName \ --template-body file://cftemplate.yaml \ --parameters ParameterKey=Subnet,ParameterValue=subnet-11111111 ParameterKey=SecurityGroups,ParameterValue=sg-111111111\\,sg-222222222 |
In the above attention to spaces and commas are important.
I verified the command using my own parameters and my sandbox account:
1 2 |
aws cloudformation create-stack --stack-name StackName --template-body file://instance.yaml --parameters ParameterKey=Subnet,ParameterValue=subnet-0ae6ce0f9bbf52251 ParameterKey=SecurityGroups,ParameterValue=sg-06d2a3e9c8aa99620\\,sg-004d23d188ec1146f |
which is correct and results in starting the process of deploying the stack:
1 2 3 4 |
{ "StackId": "arn:aws:cloudformation:us-east-1:xxxxxx:stack/StackName/61fbacd0-d3b0-11ea-970a-0ad23187ddb2" } |