AWS CLI- What is the syntax for assigning multiple values on a parameter

Viewed 2488

For example, I have this CF template that ask for these parameters

----- cftemplate.yaml -----
...
Parameters:
  **Subnet:
    Description: Subnet for the Instance
    Type: 'AWS::EC2::Subnet::Id'
  SecurityGroups: 
    Description: Security Group for Instance
    Type: 'List<AWS::EC2::SecurityGroup::Id>'**
...
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:

aws cloudformation create-stack --stack-name StackName --template-body file://cftemplate.yaml --parameters file://params.json

Where params.json contains:

----- 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!

3 Answers

The command line equivalent would be (little re-formatted for clarify):

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:

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:

{
    "StackId": "arn:aws:cloudformation:us-east-1:xxxxxx:stack/StackName/61fbacd0-d3b0-11ea-970a-0ad23187ddb2"
}

From the cli documentation,

$ aws cloudformation create-stack help

...

"--parameters" (list)

   A list of "Parameter" structures that specify input parameters for
   the stack. For more information, see the Parameter data type.

Shorthand Syntax:

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

JSON Syntax:

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

...

where the list elements are separated by space.

Related