简体   繁体   English

CloudFormation 将所有参数从根堆栈传递到嵌套堆栈

[英]CloudFormation Pass All Parameters from Root Stack to Nested Stack

Is there a way to pass every parameter that a root stack receives to its nested stacks?有没有办法将根堆栈接收到的每个参数传递给它的嵌套堆栈? I can pass one parameter at a time just fine, but I'd like to just pass them all at once.我可以一次传递一个参数就好了,但我想一次传递所有参数。

Here is sample template to give you an idea.这是给您一个想法的示例模板。

Master.yaml:大师.yaml:

Resources:
  Cloudspan:
    Type: "AWS::CloudFormation::Stack"
    Properties:
      Parameters:
        LambdaName: Cloudspan
        BucketName: <BucketName>
        S3KeyName: <S3KeyName>
        FunctionName: <FunctionName>
      TemplateURL: <TemplateURL>
  Alignment:
    Type: "AWS::CloudFormation::Stack"
    Properties:
      Parameters:
        LambdaName: Alignment
        BucketName: <BucketName>
        S3KeyName: <S3KeyName>
        FunctionName: <FunctionName>
      TemplateURL: <TemplateURL>

Lambda-child.yaml: Lambda-child.yaml:

Parameters:
  LambdaName:
    Type: String
  BucketName:
    Type: String
  S3KeyName:
    Type: String
  FunctionName:
    Type: String

Resources:
  LambdaFunction:
    Type: "AWS::Lambda::Function"
    Properties:
      Handler: !Sub '${LambdaName}-{FunctionName}.Handler'
      Role:
        Fn::GetAtt: ['LambdaExecutionRole', Arn ]
      Code:
        S3Bucket: !Sub '${LambdaName}{BucketName}'
        S3Key: !Sub '${LambdaName}{S3KeyName}'
      Runtime: "python3.6"

There is no way (yet) to pass every parameter at once from the root stack to the nested stack.没有办法(还)一次将每个参数从根堆栈传递到嵌套堆栈。 If you want to pass every parameter, you have to do it one by one as the template given in Sudharsan Sivasankaran's answer.如果要传递每个参数,则必须按照 Sudharsan Sivasankaran 的答案中给出的模板一一进行。

Fn::Import Fn::导入

You can "export" your parameters as outputs from one stack and then any stack will be able to access those values across your entire account.您可以“导出”您的参数作为一个堆栈的输出,然后任何堆栈都可以在您的整个帐户中访问这些值。 This might be more open than you are looking for but if your end goal is to get stacks to share variables then exporting outputs and referencing them with Fn::Import accomplishes that.这可能比您正在寻找的更开放,但如果您的最终目标是让堆栈共享变量,那么导出输出并使用Fn::Import引用它们就可以实现这一点。

https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/using-cfn-stack-exports.html https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/using-cfn-stack-exports.html

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM