简体   繁体   English

如何在Cloudformation中将参数从主模板发送到子模板

[英]how to send the parameters from main template to child template in cloudformation

I am trying to get two parameter from a user and then pass it to the template that I address in my main template. 我试图从用户那里获得两个参数,然后将其传递给我在主模板中处理的模板。 in my main template I have: 在我的主模板中,我有:

{
"Parameters": {
    "appName": {
        "Description": "enter the app name",
        "Type": "String",
        "Default": "bn-test-jun"
    },
    "appEnv": {
        "Description": "enter the app name",
        "Type": "String",
        "Default": "bn-test-jun"
    }
},
"Resources": {
    "CodeDeployEC2InstancesStack": {
        "Type": "AWS::CloudFormation::Stack",
        "Properties": {
            "TemplateURL": "https://s3.amazonaws.com/............../beanstalk.json",
            "TimeoutInMinutes": "60"
        }
    },
    "myS3": {
        "Type": "AWS::S3::Bucket",
        "Properties": {
            "AccessControl": "PublicRead",
            "BucketName": "ssssssss-test"
        }
    }
}
}

As you can see I am addressing the beanstalk template and I get the name of the environment and application of the beanstalk I am going to create so I need to pass these variable to the beanstalk template. 如您所见,我正在处理beantalk模板,并且获得了要创建的beantalk的环境和应用程序的名称,因此需要将这些变量传递给beantalk模板。 Here is my beanstalk template: 这是我的beantalk模板:

{
"AWSTemplateFormatVersion": "2010-09-09",
"Parameters": {
    "appName": {
        "Description": "enter the app name",
        "Type": "String",
        "Default": "bn-test-jun"
    },
    "appEnv": {
        "Description": "enter the app name",
        "Type": "String",
        "Default": "bn-test-jun"
    }
},
"Resources": {
    "sampleApplication": {
        "Type": "AWS::ElasticBeanstalk::Application",
        "Properties": {
            "Description": "AWS Elastic Beanstalk Sample Application",
            "ApplicationName": {
                "Ref": "appName"
            }
        }
    },
    "sampleApplicationVersion": {
        "Type": "AWS::ElasticBeanstalk::ApplicationVersion",
        "Properties": {
            "ApplicationName": {
                "Ref": "sampleApplication"
            },
            "Description": "AWS ElasticBeanstalk Sample Application Version",
            "SourceBundle": {
                "S3Bucket": "hamed-test-war",
                "S3Key": "deployment.war"
            }
        }
    },
    "sampleConfigurationTemplate": {
        "Type": "AWS::ElasticBeanstalk::ConfigurationTemplate",
        "Properties": {
            "ApplicationName": {
                "Ref": "sampleApplication"
            },
            "Description": "AWS ElasticBeanstalk Sample Configuration Template",
            "OptionSettings": [{
                    "Namespace": "aws:autoscaling:asg",
                    "OptionName": "MinSize",
                    "Value": "2"
                },
                {
                    "Namespace": "aws:autoscaling:asg",
                    "OptionName": "MaxSize",
                    "Value": "3"
                },
                {
                    "Namespace": "aws:elasticbeanstalk:environment",
                    "OptionName": "EnvironmentType",
                    "Value": "LoadBalanced"
                }
            ],
            "SolutionStackName": "64bit Amazon Linux 2017.03 v2.6.1 running Tomcat 8 Java 8"
        }
    },
    "sampleEnvironment": {
        "Type": "AWS::ElasticBeanstalk::Environment",
        "Properties": {
            "ApplicationName": {
                "Ref": "sampleApplication"
            },
            "Description": "AWS ElasticBeanstalk Sample Environment",
            "TemplateName": {
                "Ref": "sampleConfigurationTemplate"
            },
            "VersionLabel": {
                "Ref": "sampleApplicationVersion"
            },
            "EnvironmentName": {
                "Ref": "appEnv"
            }
        }
    }
},
"Outputs": {
    "applicationName11": {
        "Description": "The application chosen by user is :",
        "Value": {
            "Ref": "appEnv"
        }
    }
}

} }

As you see I am trying to use Ref appname to get the variable but this does not work because the appname in available only in the parent template. 如您所见,我正在尝试使用ref appname来获取变量,但这不起作用,因为appname仅在父模板中可用。 So I am looking for a way to send the param to the beanstalk.template. 因此,我正在寻找一种将参数发送到beantalk.template的方法。 Is it possible to do that? 有可能这样做吗?

It seems you are using nested stacks to pull in the template. 似乎您正在使用嵌套堆栈来拉入模板。 If so a Parameters property can be used to pass your parameters in to the child template as shown here: 如果是这样,可以使用Parameters属性将参数传递到子模板中,如下所示:

{
   "AWSTemplateFormatVersion" : "2010-09-09",
   "Resources" : {
      "myStackWithParams" : {
         "Type" : "AWS::CloudFormation::Stack",
         "Properties" : {
            "TemplateURL" : "https://s3.amazonaws.com/cloudformation-templates-us-east-1/EC2ChooseAMI.template",
            "Parameters" : {
               "InstanceType" : "t1.micro",
               "KeyName" : "mykey"
            }
         }
      }
   }
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 从参数中在cloudformation模板中命名? - naming in cloudformation template from the parameters? cloudformation模板中的opsworks参数和资源 - opsworks parameters and resources in the cloudformation template 如何从多个 yml 构建 CloudFormation 模板 - How to build CloudFormation template from multiple yml 如何从RDS生成AWS CloudFormation模板 - How to generate AWS CloudFormation template from an RDS 如何从 SAm 项目创建 cloudformation 模板? - How to create cloudformation template from SAm project? 如何在Cloudformation模板参数中创建IAM角色下拉列表 - How can I create IAM Role Dropdown in Cloudformation Template Parameters 如何获取 cloudformation 模板中的参数以使用 Amazon Go SDK 启动? - How to get parameters in cloudformation template to launch using Amazon Go SDK? 尝试将参数从Master传递到子模板 - Trying to pass parameters from Master to child template AWS CloudFormation:如何在cloudformation模板中引用默认/主路由表(在创建VPC时创建)? - AWS CloudFormation: how do I refer to the default/main route table (that is created when a VPC is created) in a cloudformation template? 如何在新的 Cloudformation 模板中引用 Cloudformation 资源? - How to reference Cloudformation Ressources in a new Cloudformation template?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM