Amazon web services 无法在cloudformation的父模板中使用内部(子)模板的输出
我试图在另一个系统中使用cloudformation堆栈的输出。我看了一些examoles,比如 但这非常令人困惑,在我的示例中,我无法使其工作: 以下是我所拥有的:我有一个beanstalk.json模板,并输出我在参考资料部分创建的sampleEnvironment:Amazon web services 无法在cloudformation的父模板中使用内部(子)模板的输出,amazon-web-services,amazon-cloudformation,Amazon Web Services,Amazon Cloudformation,我试图在另一个系统中使用cloudformation堆栈的输出。我看了一些examoles,比如 但这非常令人困惑,在我的示例中,我无法使其工作: 以下是我所拥有的:我有一个beanstalk.json模板,并输出我在参考资料部分创建的sampleEnvironment: { "AWSTemplateFormatVersion": "2010-09-09", "Resources": { "sampleApplication": { "Type": "AWS::Elas
{
"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的名称。以下是我的主要tempalte代码:
{
"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 bucket的名称。如何才能做到这一点?导出参数需要有一个可供其他堆栈访问的参数: 导出(可选) 要为跨堆栈引用导出的资源输出的名称 注意 以下限制适用于跨堆栈引用:
- 对于每个AWS帐户,导出名称在区域内必须是唯一的
- 不能跨区域创建跨堆栈引用李>
- 您可以使用内在函数Fn::ImportValue仅导入已在同一区域内导出的值
- 对于输出,导出的Name属性的值不能使用依赖于资源的Ref或GetAtt函数。类似地,ImportValue函数不能包含依赖于资源的Ref或GetAtt函数
- 如果另一个堆栈引用其输出之一,则无法删除该堆栈
- 不能修改或删除由另一个堆栈引用的输出值
"Outputs": {
"applicationName11": {
"Description": "The application chosen by user is :",
"Value": {
"Ref": "sampleEnvironment"
},
"Export" : {
"Name" : {
"Fn::Join" : [ "-", [ { "Ref" : "AWS::StackName" }, {"Ref": "something"} ] ]
}
}
}
}
然后,您可以在必要时通过Fn::ImportValue导入它。AWS有一个。导出参数需要有一个可供其他堆栈访问的参数: 导出(可选) 要为跨堆栈引用导出的资源输出的名称 注意 以下限制适用于跨堆栈引用:
- 对于每个AWS帐户,导出名称在区域内必须是唯一的
- 不能跨区域创建跨堆栈引用李>
- 您可以使用内在函数Fn::ImportValue仅导入已在同一区域内导出的值
- 对于输出,导出的Name属性的值不能使用依赖于资源的Ref或GetAtt函数。类似地,ImportValue函数不能包含依赖于资源的Ref或GetAtt函数
- 如果另一个堆栈引用其输出之一,则无法删除该堆栈
- 不能修改或删除由另一个堆栈引用的输出值
"Outputs": {
"applicationName11": {
"Description": "The application chosen by user is :",
"Value": {
"Ref": "sampleEnvironment"
},
"Export" : {
"Name" : {
"Fn::Join" : [ "-", [ { "Ref" : "AWS::StackName" }, {"Ref": "something"} ] ]
}
}
}
}
然后,您可以在必要时通过Fn::ImportValue导入它。AWS有一个问题。我已经在CFN课程论坛上回复了
您不需要使用导出/导入值,因为您使用的是嵌套堆栈。我已经在CFN课程论坛上回复了
您不需要使用导出/导入值,因为您使用的是嵌套堆栈。我在添加导出的第一个输出中更新了代码,在主模板输出中添加了导入以获取值并显示它。仍不工作并出现以下错误:未找到名为sampleEnvironment的导出。有什么想法吗?我在添加导出的第一个输出中更新了代码,在主模板输出中添加了导入以获取值并显示它。仍不工作并出现以下错误:未找到名为sampleEnvironment的导出。有什么想法吗?