Back

Explore Courses Blog Tutorials Interview Questions
0 votes
1 view
in AWS by (5.6k points)

I have a CloudFormation template that asks 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 -----

Now for deploying stack, I'm using the below command:

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

And params.json have:

---- params.json ----- 

[

        {

            "ParameterKey":"Subnet",

            "ParameterValue":"subnet-11111111"

        },

        {

            "ParameterKey":"SecurityGroups",

            "ParameterValue":"sg-111111111",

            "ParameterValue":"sg-222222222"

        } 

]

----- params.json -----

Now I want to eliminate the use of JSON, Can anyone help me with the shorthand syntax for the command that should provide the same effect as the above code?

1 Answer

0 votes
by (12.4k points)

The CLI would be:

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

Verify the command using your parameters:

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

and should result in deploying stack:

{

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

}

Want to become AWS Expert? Come & join AWS Certification.

Do watch the below video tutorial on CloudFormation. 

Related questions

0 votes
1 answer

Want to get 50% Hike on your Salary?

Learn how we helped 50,000+ professionals like you !

0 votes
1 answer
asked Mar 3, 2021 in AWS by devin (5.6k points)
0 votes
1 answer

Browse Categories

...