Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to pass parameter as a file in AWS CloudFormation deploy?

I was trying to update the existing CloudFormation stack with the below command.

aws cloudformation deploy

there is no option to pass parameter file with deploy option. we tried to pass parameter file with --parameter-overrides but it's giving the below error.

value passed to --parameter-overrides must be of format Key=Value

the command we try to execute is

aws cloudformation deploy --template-file sg.yml --stack-name Common-SG --parameter-overrides ip.json --no-execute-changeset

is there any way to pass the parameters in file with aws cloudformation deploy

like image 258
mahendra rathod Avatar asked Jun 22 '20 19:06

mahendra rathod


People also ask

How do you reference a parameter in CloudFormation?

Referencing a parameter within a template You use the Ref intrinsic function to reference a parameter, and AWS CloudFormation uses the parameter's value to provision the stack. You can reference parameters from the Resources and Outputs sections of the same template.

How do you pass parameters in Codepipeline?

We recommend that you use the template configuration file to specify most of your parameter values. Use parameter overrides to specify dynamic parameter values only. Dynamic parameters are unknown until you run the pipeline. Keep in mind that there is a 1KB limit on the size of parameter overrides too.

What is pseudo parameter in AWS CloudFormation?

Pseudo parameters are parameters that are predefined by AWS CloudFormation. You don't declare them in your template. Use them the same way as you would a parameter, as the argument for the Ref function.


3 Answers

Passing a parameters stored as JSON in a local file looks like:

aws cloudformation deploy \
    --stack-name demo \
    --template-file test.yml --parameter-overrides file://test.json  \

and the test.json like this.

{
    "Parameters": {
      "BucketName": "myawesometestdemo"
    }
}

test.yml

---
AWSTemplateFormatVersion: '2010-09-09'
Description: Simple S3 Bucket test
Parameters:
  BucketName:
    Type: String
    Description: The name of the S3 Bucket to create

Metadata:

  AWS::CloudFormation::Interface:
    ParameterLabels:
      BucketName:
        default: S3 Bucket Name

Resources:

  S3Bucket:
    Type: AWS::S3::Bucket
    Properties:
      BucketName: !Ref BucketName

aws cli version :

aws --version
aws-cli/2.2.35 Python/3. XXX
like image 166
Christophe Grall Avatar answered Oct 25 '22 00:10

Christophe Grall


workaround for this issue is pass parameters with jq command.

yum install jq

Below is the syntax for the same.

aws cloudformation deploy --template-file sg.yml --stack-name Common-SG --parameter-overrides $(jq -r '.[] | [.ParameterKey, .ParameterValue] | "\(.[0])=\(.[1])"' ip.json) --no-execute-changeset
like image 39
mahendra rathod Avatar answered Oct 24 '22 23:10

mahendra rathod


this might be too late already, but for the sake of future similar issue I found this answer on (https://github.com/aws/serverless-application-model/issues/111)

The command should look like:

aws cloudformation deploy --template-file sg.yml --stack-name Common-SG --parameter-overrides $(cat params.properties) --no-execute-changeset

Now this is not going to be a json file, since "parameter-overrieds" expects a Key=Value pairs!

like image 39
Dean Avatar answered Oct 25 '22 00:10

Dean