【问题标题】:How the Cloud formation template in yaml will be for checking whether the exported stack is exists or not (Using nested? stack)yaml 中的云形成模板将如何检查导出的堆栈是否存在(使用嵌套?堆栈)
【发布时间】:2021-08-18 12:02:39
【问题描述】:

基于以下代码尝试实现 YAML 模板,并想检查导出的堆栈是否存在。请建议方法。

Outputs:
  PublicSubnet:
    Description: The subnet ID to use for public web servers
    Value:
      Ref: PublicSubnet
    Export:
      Name:
        'Fn::Sub': '${AWS::StackName}-SubnetID'
  WebServerSecurityGroup:
    Description: The security group ID to use for public web servers
    Value:
      'Fn::GetAtt':
        - WebServerSecurityGroup
        - GroupId
    Export:
      Name:
        'Fn::Sub': '${AWS::StackName}-SecurityGroupID'

Resources:
  WebServerInstance:
    Type: 'AWS::EC2::Instance'
    Properties:
      InstanceType: t2.micro
      ImageId: ami-a1b23456
      NetworkInterfaces:
        - GroupSet:
            - !ImportValue 
              'Fn::Sub': '${NetworkStackNameParameter}-SecurityGroupID'
          AssociatePublicIpAddress: 'true'
          DeviceIndex: '0'
          DeleteOnTermination: 'true'
          SubnetId: !ImportValue 
            'Fn::Sub': '${NetworkStackNameParameter}-SubnetID'

【问题讨论】:

    标签: yaml amazon-cloudformation nested-stack


    【解决方案1】:

    使用普通的 CloudFormation (CFN) 无法做到这一点。导出的值桅杆已经存在,您无法使用 CFN 检查它是否存在。

    唯一的方法是以 lambda 函数的形式创建 custom resource。该函数将使用 AWS SDK 检查给定的导出是否存在,并将检查结果返回到您的模板以进行进一步处理。

    【讨论】:

    • 感谢您的建议。因为我是 aw 的新手,如果有的话,请你分享一下示例代码/doc。
    • @chandra9 没问题。我已经链接了自定义资源文档。您将在那里找到自定义资源的示例。
    猜你喜欢
    • 1970-01-01
    • 2017-05-16
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-10-31
    • 2012-12-31
    • 2015-02-15
    相关资源
    最近更新 更多