![](/img/trans.png)
[英]How to import cloudformation stack output inside another stack parameter?
[英]AWS/Cloudformation: How to export/import parameter value to another stack (YAML)
我有一个简单的问题。 我正在测试云形成中值的导出/导入。
问题是:如何根据来自另一个堆栈的链接条件创建资源?
我想我应该从其他堆栈导入值,但不知道如何......
这是我的“出口测试堆栈”
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
这是我的“导入测试堆栈”
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
这是关于跨堆栈引用的,所以只有当我选择在之前的“export-test-stack”中部署三个实例时,我才想在“import-test-stack”中部署 Ec2Instance2。 这个怎么做?
所以如果我选择部署三个实例,我想使用“import stack”中的条件来部署另外两个实例,如果我选择部署两个,它只会在“import-stack”中部署一个实例
我知道条件如何工作,但仍然无法找到方法,如何在交叉引用堆栈中使用。
我知道这是一个愚蠢的例子,但我只是想在尽可能简单的模板上进行测试。
您有两种选择:继续使用分离的堆栈或组合它们以创建嵌套堆栈。
使用嵌套堆栈,您可以使用一个堆栈的输出作为另一个堆栈的输入。
如果您想继续使用分离的堆栈,请使用Fn::ImportValue
函数来导入从另一个堆栈导出的输出值。
导出堆栈输出值页面中已涵盖这两个角度。 此外,如果您选择使用Fn::ImportValue
, 跨堆栈参考演练可能会对您有所帮助。
这将使您导入正确的值: Fn::ImportValue: EC2Conditions
您也可以使用规则。 您可以根据输出的值来制定规则。
我们不能在这里使用导入值,因为 cloudformation 不允许在参数中使用内在值。 但是有一个在 AWS 中使用 SSM(AWS 系统管理参数存储)参数的选项,它允许我们使用在堆栈 A 中创建的堆栈 B 中的参数
请查看以下来自 AWS 知识中心的文章链接
https://aws.amazon.com/premiumsupport/knowledge-center/cloudformation-systems-manager-parameter/
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.