[英]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.