Search code examples
aws-cloudformationaws-parameter-store

CloudFormation Template to accept parameter from external file


I am trying to achieve the same thing but for Parameter Store. My scenario is, Developers will provide a .json file with key/value. That file should be used by the CloudFormation template to create Parameter Store resources based on the entry made as a json file.

Main template -

    {
"AWSTemplateFormatVersion": "2010-09-09",
"Parameters": {
    "SSMParameterStore": {
        "Description": "SSM Parameter Store",
        "Type": "String"
    }
},
"Resources": {
        "InputParameters": {
            "Type": "AWS::SSM::Parameter",
            "Properties": {
                "Name": {"Ref": "ParameterKey"},
                "Type": "String",
                "Value": {"Ref": "ParameterValue"}
            }
        }
    }
}

Input Template -

[{
"ParameterKey": "KeyPairName",
"ParameterValue": "MyKey"
},
{
"ParameterKey": "InstanceType",
"ParameterValue": "m1.micro"
}
]

Command:

aws cloudformation create-stack --stack-name test --template-body file:///home/user/Documents/Work/training/test/templt.json --parameters file:///home/user/Documents/Work/training/test/test.json --region us-east-1

Output:

An error occurred (ValidationError) when calling the CreateStack operation: Parameters: [SSMParameterStore] must have values

Not sure what is missing here.


Solution

  • Your template has a parameter of SSMParameterStore but you are passing in KeyPairName and InstanceType.