【问题标题】:cloudformation delay resource creation within the same stackcloudformation 延迟在同一堆栈内创建资源
【发布时间】:2021-09-25 04:41:55
【问题描述】:

是否可以在同一个堆栈中延迟资源创建?我有一个 DC 和另一台服务器,一旦 DC 全部设置好,它就需要加入域。两台服务器都在同一个堆栈中创建。我尝试使用等待句柄,但它仍然同时创建两个资源,然后在等待句柄期间显示正在进行创建。

编辑:要求的代码: 1. DC服务器的用户数据

        # "Fn::Base64":
    #   Fn::Join ["", [
    #   "<script>cfn-init -v --stack ", !Ref "AWS::StackName", " --resource DC --configsets ascending --region", !Ref "AWS::Region", "\n",
    #   "cfn-signal.exe -e 0 ", Fn::Base64 !Ref DCServerWaitHandle, "</script>"]]

等待句柄

DCServerWaitHandle:
  Type: AWS::CloudFormation::WaitConditionHandle
DCServerWaitCondition:
  Type: AWS::CloudFormation::WaitCondition
  DependsOn: DC
  Properties:
    Handle: !Ref DCServerWaitHandle
    Timeout: 600

那么应该等待 600 秒以使 DC 构建的另一台服务器具有依赖项:DC 属性

【问题讨论】:

    标签: amazon-web-services amazon-cloudformation


    【解决方案1】:

    通常您可以使用 DependsOn 功能来按顺序创建资源。 特别是对于 EC2 实例,您可以使用 CreationPolicy Attribute 来防止资源进入完成状态。

    来自docs

    对于 Amazon EC2 和 Auto Scaling 资源,我们建议您使用 CreationPolicy 属性而不是等待条件。为这些资源添加 CreationPolicy 属性,并使用 cfn-signal 帮助程序脚本在实例创建过程成功完成时发出信号。

    【讨论】:

      【解决方案2】:

      这是一个自定义资源,可用作任意资源的延迟。只需添加几个 DependsOn,您就可以开展业务了。

      https://github.com/aws-cloudformation/cloudformation-coverage-roadmap/issues/589

      例如:

         TGWAttachmentPeering:
            Condition: CreateTGWPeering
            Type: AWS::EC2::TransitGatewayPeeringAttachment
            Properties: 
              PeerAccountId: !Ref AWS::AccountId
              PeerRegion: !FindInMap [RegionMap, !Ref AWS::Region, opposite]
              PeerTransitGatewayId: !Ref PeerTransitGatewayId
              TransitGatewayId: !Ref TransitGateway
            CreationPolicy:
              ResourceSignal:    
                Count: Integer
                Timeout: String
      
      
          TGWRouteTable:
            Condition: CreateTGWPeering
            Type: AWS::EC2::TransitGatewayRouteTable
            Properties:
              Tags:
                - Key: Name
                  Value: !Sub VPC-${VPCNumber}
              TransitGatewayId: !Ref TransitGateway
      
          Delay: #https://github.com/aws-cloudformation/cloudformation-coverage-roadmap/issues/589#issuecomment-671111145
            Condition: CreateTGWPeering
            DependsOn: TGWAttachmentPeering
            Type: Community::CloudFormation::Delay
            Properties:
              Duration: PT300S
      
          TGWPeeringRoute:
            Condition: CreateTGWPeering
            DependsOn: Delay
            Type: AWS::EC2::TransitGatewayRoute
            Properties:
              DestinationCidrBlock: 
                !Sub 
                  - 1.${cidrRange}.0.0/16
                  - cidrRange: !FindInMap [VPCMap, !Ref VPCNumber, opposite]
              TransitGatewayRouteTableId: !Ref TGWRouteTable
              TransitGatewayAttachmentId: !Ref TGWAttachmentPeering
      

      【讨论】:

        猜你喜欢
        • 2020-11-09
        • 1970-01-01
        • 2021-04-22
        • 2021-07-06
        • 1970-01-01
        • 2019-05-09
        • 1970-01-01
        • 2021-01-16
        • 1970-01-01
        相关资源
        最近更新 更多