[英]AWS/Cloudformation: How to export/import parameter value to another stack (YAML)
I have a simple question.我有一个简单的问题。 I am testing export/import of values in cloud formation.
我正在测试云形成中值的导出/导入。
Question is: How to create resources based on linked conditions from another stack?问题是:如何根据来自另一个堆栈的链接条件创建资源?
I think I should import the value from other stack, but don't know how....我想我应该从其他堆栈导入值,但不知道如何......
This is my "export-test-stack"这是我的“出口测试堆栈”
AWSTemplateFormatVersion: '2010-09-09' Description: Export Parameters: EnvType: Description: How many Instances you want to deploy? Default: two Type: String AllowedValues: - two - three ConstraintDescription: must specify number of deployed Instances Conditions: Deploy3EC2: ,Equals [:Ref EnvType: three ] Resources: Ec2Instance1: Type: AWS::EC2::Instance Properties. InstanceType: t2:micro SecurityGroupIds: - sg-5d011027 ImageId: ami-0b33d91d Ec2Instance2: Type: AWS::EC2::Instance Properties. InstanceType: t2:micro SecurityGroupIds: - sg-5d011027 ImageId: ami-0b33d91d Ec2Instance3: Type: AWS::EC2::Instance Condition: Deploy3EC2 Properties. InstanceType: t2:micro SecurityGroupIds: - sg-5d011027 ImageId: ami-0b33d91d Outputs: EC2Conditions: Description: Number of deployed instances Value: !Ref EnvType Export: Name: blablabla
This is my "import-test-stack"这是我的“导入测试堆栈”
AWSTemplateFormatVersion: '2010-09-09' Description: Import Resources: Ec2Instance1: Type: AWS::EC2::Instance Properties: InstanceType: t2.micro SecurityGroupIds: - sg-7309dd0a ImageId: ami-70edb016 Ec2Instance2: Type: AWS::EC2::Instance Condition: ?????? <<<<<<<<< Properties: InstanceType: t2.micro SecurityGroupIds: - sg-7309dd0a ImageId: ami-70edb016
It's about cross stack reference, so I want to deploy Ec2Instance2 in "import-test-stack" only if I choose to deploy three Instances in previous "export-test-stack".这是关于跨堆栈引用的,所以只有当我选择在之前的“export-test-stack”中部署三个实例时,我才想在“import-test-stack”中部署 Ec2Instance2。 How to do this?
这个怎么做?
So if I choose to deploy three instances, I want to use condition in "import stack" to deploy another two instances, if I choose to deploy two, it will deploy only one instance in "import-stack"所以如果我选择部署三个实例,我想使用“import stack”中的条件来部署另外两个实例,如果我选择部署两个,它只会在“import-stack”中部署一个实例
I know how conditions working, but still not able to find the way, how to use in cross reference stacks.我知道条件如何工作,但仍然无法找到方法,如何在交叉引用堆栈中使用。
I know it's stupid example, but I just wanted to test that on as simple template as possible.我知道这是一个愚蠢的例子,但我只是想在尽可能简单的模板上进行测试。
You have two choices: continue with separated stacks or combine them to create a nested stack.您有两种选择:继续使用分离的堆栈或组合它们以创建嵌套堆栈。
With nested stacks you can use outputs from one stack as inputs to another stack.使用嵌套堆栈,您可以使用一个堆栈的输出作为另一个堆栈的输入。
If you want to keep using separated stacks use Fn::ImportValue
function to import output values exported from another stack.如果您想继续使用分离的堆栈,请使用
Fn::ImportValue
函数来导入从另一个堆栈导出的输出值。
The both angles have been covered in Exporting Stack Output Values page. 导出堆栈输出值页面中已涵盖这两个角度。 Also, the cross-stack reference walkthrough might help you if you choose to use
Fn::ImportValue
.此外,如果您选择使用
Fn::ImportValue
, 跨堆栈参考演练可能会对您有所帮助。
This will get you to import the correct value: Fn::ImportValue: EC2Conditions这将使您导入正确的值: Fn::ImportValue: EC2Conditions
You can also use rules.您也可以使用规则。 You can make the rule be based on the value of your output.
您可以根据输出的值来制定规则。
we cannot use import value here as cloudformation does not allow to use intrinsic values in the parameter.我们不能在这里使用导入值,因为 cloudformation 不允许在参数中使用内在值。 But there is an option of using SSM (AWS System Management parameter store ) parameters in AWS which allows us to use the parameter in stack B which is created in stack A
但是有一个在 AWS 中使用 SSM(AWS 系统管理参数存储)参数的选项,它允许我们使用在堆栈 A 中创建的堆栈 B 中的参数
Please check the link below article from AWS knowledge center请查看以下来自 AWS 知识中心的文章链接
https://aws.amazon.com/premiumsupport/knowledge-center/cloudformation-systems-manager-parameter/ https://aws.amazon.com/premiumsupport/knowledge-center/cloudformation-systems-manager-parameter/
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.