【发布时间】:2017-12-06 00:57:13
【问题描述】:
我正在尝试在另一个中使用 cloudformation 堆栈的输出。我查看了一些示例,例如 https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/walkthrough-crossstackref.html
但它非常令人困惑,我无法在我的示例中使用它:
这是我所拥有的:我有一个 beanstalk.json 模板,我输出了我在资源部分创建的 sampleEnvironment:
{
"AWSTemplateFormatVersion": "2010-09-09",
"Resources": {
"sampleApplication": {
"Type": "AWS::ElasticBeanstalk::Application",
"Properties": {
"Description": "AWS Elastic Beanstalk Sample Application",
"ApplicationName": "app-name-test"
}
},
"sampleApplicationVersion": {
"Type": "AWS::ElasticBeanstalk::ApplicationVersion",
"Properties": {
"ApplicationName": {
"Ref": "sampleApplication"
},
"Description": "AWS ElasticBeanstalk Sample Application Version",
"SourceBundle": {
"S3Bucket": "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": "test-dep-env-name"
}
}
},
"Outputs": {
"applicationName11": {
"Description": "The application chosen by user is :",
"Value": {
"Ref": "sampleEnvironment"
},
"Export" : {
"Name" : {"Ref": "sampleEnvironment"}
}
}
}
现在我的问题开始了。我需要参考在 beanstalk.json 中创建的 sampleEnvironment 的名称,并将其分配给使用 beanstalk.json 模板的主模板中资源部分的 s3 的名称。这是我的主要模板代码:
{
"Parameters": {
"appName1": {
"Description": "enter the app name",
"Type": "String",
"Default": "bn-test-jun"
},
"appEnv1": {
"Description": "enter the app name",
"Type": "String",
"Default": "bn-test-jun"
}
},
"Resources": {
"CodeDeployEC2InstancesStack": {
"Type": "AWS::CloudFormation::Stack",
"Properties": {
"TemplateURL": "https://s3.amazonaws.com/url...../beanstalk.json",
"TimeoutInMinutes": "60"
}
},
"myS3": {
"Type": "AWS::S3::Bucket",
"Properties": {
"AccessControl": "PublicRead",
"BucketName": "name of the environment returned as an output sth like Outputs.EnvironmentName"
}
}
}
,
"Outputs":{
"app":{
"Description": "The application chosen by user is :",
"Value": {
"Fn::ImportValue" : "sampleEnvironment"
}
}
}
}
现在您在 bucketName 部分看到我被卡住了。我需要将 beanstalk.json 中创建的环境的名称分配给将要创建的 s3 存储桶的名称。我该怎么做?
【问题讨论】:
标签: amazon-web-services amazon-cloudformation