【问题标题】:AWS CloudFront - Importing a parameter as a "global" parameter across cloudfront stacksAWS CloudFront - 将参数导入为跨云端堆栈的“全局”参数
【发布时间】:2021-04-07 23:59:55
【问题描述】:

我想从我正在运行的堆栈中导出一个值,然后将其作为“全局”参数导入另一个堆栈,以便我可以对其进行操作并将其用作 S3 存储桶名称。我已经知道我可以使用以下方法在资源中的一行上单独导入值:

{ "Fn::ImportValue" : { "Fn::Sub" : "${StackName}-ParameterName" } }

但是有没有办法将它导入我的参数部分?

感谢您的帮助

【问题讨论】:

    标签: json amazon-web-services import amazon-cloudformation


    【解决方案1】:

    但是有没有办法将它导入我的参数部分?

    没有这样的选择。最接近的方法是将全局值保存在 SSM Parameter Store 中,并将 CloudFormation 中的 dynamic references 用作 Parameters 中的 Default 值。

    【讨论】:

      【解决方案2】:

      有两种方法可以实现这一点

      1. 使用SSM Parameter Store,将值从源堆栈存储到SSM参数存储

             BasicParameter:
             Type: AWS::SSM::Parameter
             Properties:
             Name: AvailabilityZone
             Type: String
             Value:
                 Ref: AvailabilityZone
        

      然后将值直接引用到参数部分,如下所示:

          ---
          AWSTemplateFormatVersion: '2010-09-09'
          Parameters:
          ...
          AvailabilityZone:
              Description: Amazon EC2 instance Availablity Zone
              Type: AWS::SSM::Parameter::Value<String>
              Default: AvailabilityZone
          Mappings: {}
          Conditions: {}
          Resources:
          myinstance:
              Type: AWS::EC2::Instance
              Properties:
              AvailabilityZone:
                  Ref: AvailabilityZone
                  ...
      

      完整的例子可以在here找到

      1. 您在启动堆栈时使用源堆栈的输出并将它们传递到目标堆栈。

      源堆栈输出配置

          Outputs:
          InstanceID:
              Description: The Instance ID
              Value: !Ref EC2Instance
      

      在目标堆栈中使用它们:

              aws \
              --region us-east-1 \
              cloudformation deploy \
              --template-file cfn.yml \
              --stack-name mystack \
              --no-fail-on-empty-changeset \
                          --tags Application=awesomeapp \
              --parameter-overrides \
                                          "Somevar=OUTUT_FROM_SOURCE_STACK" 
      

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 2018-12-13
        • 1970-01-01
        • 2017-08-21
        • 2022-01-19
        • 2020-12-13
        • 2020-06-01
        • 2020-08-17
        • 2013-10-21
        相关资源
        最近更新 更多