Reputation: 13
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.
Upvotes: 1
Views: 2682
Reputation: 13
Answering to my own post with bit advancement.
Below is the working template.
Master Template -
{
"AWSTemplateFormatVersion": "2010-09-09",
"Parameters": {
"KeyPairName": {
"Description": "ssm key",
"Type": "String"
},
"KeyPairValue": {
"Description": "Value",
"Type": "String"
},
"KeyPairName1": {"Description": "ssm key", "Type": "String"},
"KeyPairValue1": {"Description": "ssm key", "Type": "String"}
},
"Resources": {
"InputParameters": {
"Type": "AWS::SSM::Parameter",
"Properties": {
"Name": {"Ref": "KeyPairName"},
"Type": "String",
"Value": {"Ref": "KeyPairValue"}
}
},
"InputParamters": {
"Type": "AWS::SSM::Parameter",
"Properties": {
"Name": {"Ref": "KeyPairName1"},
"Type": "String",
"Value": {"Ref": "KeyPairValue1"}
}
}
}
}
Parameter Template -
[
{
"ParameterKey": "KeyPairName",
"ParameterValue": "/config/dev/ms/FIRST_NAME"
},
{
"ParameterKey": "KeyPairValue",
"ParameterValue": "MY_F_NAME"
},
{
"ParameterKey": "KeyPairName1",
"ParameterValue": "/config/dev/ms/LAST_NAME"
},
{
"ParameterKey": "KeyPairValue1",
"ParameterValue": "MY_L_NAME"
}
]
But the problem is that I have to keep updating the master template manually every time when there is a new key/value in the parameter template file. I still couldn't find a way to do this dynamically where irrespective of a number of entries in parameter file my template should take all key/value and create/update resources in Parameter Store. It seems that writing a Python or Bash wrapper may do this.
Upvotes: 0
Reputation: 8885
Your template has a parameter of SSMParameterStore
but you are passing in KeyPairName
and InstanceType
.
Upvotes: 2