简体   繁体   English

AWS/Cloudformation:如何将参数值导出/导入到另一个堆栈 (YAML)

[英]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.

相关问题 如何在另一个堆栈参数中导入 cloudformation 堆栈 output? - How to import cloudformation stack output inside another stack parameter? 如何通过 CloudFormation 将堆栈导出的现有 S3 存储桶导入另一个堆栈 YAML - How to import an existing S3 bucket exported by a stack, into another stack via CloudFormation YAML AWS CloudFormation 导出 yaml 文件 - AWS CloudFormation export yaml file 如何从 aws 参数存储中导出参数并导入另一个帐户 - How to export parameters from aws parameter store and import into another account 如何在 aws cloudformation yaml 模板中格式化数据类型 json 的参数? - How to format parameter of data type json in a aws cloudformation yaml template? 如何将默认 VPC 导入 CloudFormation 堆栈并使用 AWS CDK 重新创建它? - How to import default VPC into CloudFormation stack and recreate it with AWS CDK? 如何将列表传递给AWS CloudFormation中的嵌套堆栈参数? - How to pass a list to a nested stack parameter in AWS CloudFormation? 如何从 CloudFormation 中的另一个堆栈导入现有的 S3 存储桶? - How to import existing S3 bucket from another stack in CloudFormation? AWS Cloudformation-如何依赖另一个嵌套堆栈中的DependsOn资源 - AWS Cloudformation - how to DependsOn resource from another nested stack 将参数添加到 AWS CloudFormation / CodePipeline 堆栈 - Add parameter to an AWS CloudFormation / CodePipeline stack
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM