无法在cloudformation的父模板中使用内部(子)模板的输出 [英] Cannot use the output of the inner (child ) template in the parent template in cloudformation

查看:91
本文介绍了无法在cloudformation的父模板中使用内部(子)模板的输出的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图在另一个中使用cloudformation堆栈的输出。我看了一些例子,例如
https:/ /docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/walkthrough-crossstackref.html

I am trying to use the output of a cloudformation stack in another. I looked at some examoles such as https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/walkthrough-crossstackref.html

,但是这非常令人困惑,我无法做到在我的示例中工作:

but it is very confusing and I could not make it work in my example:

这是我拥有的:我有一个beantalk.json模板,并且输出在资源部分中创建的sampleEnvironment:

here is what I have: I have a beanstalk.json template and I output the sampleEnvironment I created in resource section:

{
"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的名称,并将其分配给使用beantalk.json模板的主模板中资源部分中s3的名称。这是我的主要临时代码:

Now my problem starts. I need to refer to the name of the sampleEnvironment created in beanstalk.json and assign it to the name of the s3 in resource section in the main template which uses beanstalk.json template. Here is my main tempalte code:

{
"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存储桶的名称。我该怎么办?

Now you see that in the bucketName section I am stuck. I need to assign the name of the environment created in beanstalk.json to the name of the s3 bucket which is going to be created. How can I do that?

推荐答案

我在CFN课程论坛上回答了

I've replied on the CFN course forums

https://acloud.guru/forums/ aws-advanced-cloudformation / discussion / -KoAxjlT_ZtSAdrlg1lp / cannot_use_the_output_of_the_i

您无需使用Export / Import值,因为您使用的是嵌套堆栈。

You dont need to use Export/Import value because you are using nested stacks.

这篇关于无法在cloudformation的父模板中使用内部(子)模板的输出的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆