Passing Parameters in Nested Cloud Formation templ

2020-06-29 02:24发布

问题:

I am calling CFT2 from CFT1 and I am passing a list of parameters.I recently came to know that we cant pass comma delimited list of parameters, so I am looking how to achieve that solution . This is my CFT1 :

{
    "AWSTemplateFormatVersion": "2010-09-09",
    "Description": "Top Stack",
   "Resources": {
   "ChildStack01": {
           "Type" : "AWS::CloudFormation::Stack",
           "Properties" : {
               "TemplateURL": "https://s3.amazonaws.com/tbdchef/frontend1.json",
               "Parameters": {
                "AvailabilityZone1a": {
                    "Default": "us-east-1a",
                    "Description": "us-east-1a",
                    "Type": "String"
                },
                "AvailabilityZone1b": {
                    "Default": "us-east-1b",
                    "Description": "us-east-1b",
                    "Type": "String"
                },
                "ChefDevSNSTopic": {
                    "Description": "ARNforSNSTopic",
                    "Type": "String",
                    "Default": "arn:aws:sns:us-east-1:093937234853:Enterprise_Monitoring_SNS_Horizontal"
                }
               },
              "TimeoutInMinutes" : "5"
           }
        }
    }
}

The error I am getting :

Value of property Parameters must be an object with String (or simple type) properties

Is there a way I can pass these values to CFT2?

回答1:

You can pass this in this way

{
"AWSTemplateFormatVersion": "2010-09-09",
    "Parameters": {
        "KeyName": {
            "Description": "Name of an existing EC2 KeyPair to enable SSH access to the instance",
            "Type": "AWS::EC2::KeyPair::KeyName",
            "ConstraintDescription": "must be the name of an existing EC2 KeyPair."
        },
    },
    "Resources": {
        "ChildStack01": {
           "Type" : "AWS::CloudFormation::Stack",
           "Properties" : {
               "TemplateURL": "https://s3.amazonaws.com/tbdchef/frontend1.json",
               "Parameters": {
                         "KName":  { "Ref" : "KeyName" }
                }
            }
        }
    }
}

And then again defining the parameter KName in CFT2

{
   "AWSTemplateFormatVersion": "2010-09-09",
   "Parameters": {
        "KName": {
            "Description": "Name of an existing EC2 KeyPair to enable SSH access to the instance",
            "Type": "AWS::EC2::KeyPair::KeyName",
            "ConstraintDescription": "must be the name of an existing EC2 KeyPair."
        }
    }
}