在 CloudFormation 中使用 Depends On 的最佳實踐是什么?我相信從我讀到的內容來看,不建議在 Azure 中這樣做并盡量減少它的使用。
例如,我想在 ASG 策略和 ASG 組之間建立 DependsOn 關系。

在上圖中,您可以看到 ASG Policy 有一個欄位AutoScalingGroupName。
因此,ASG 策略取決于 AutoScaling 組的創建。
這兩者之間是否存在依賴關系?
uj5u.com熱心網友回復:
通常,CloudFormation 模板中參考另一個資源的任何資源都將自動具有隱含 DependsOn的.
例如:
PrivateRouteTable1:
Type: AWS::EC2::RouteTable
Properties:
VpcId: !Ref VPC
Tags:
- Key: Name
Value: !Sub ${EnvironmentName} Private Routes (AZ1)
DefaultPrivateRoute1:
Type: AWS::EC2::Route
Properties:
RouteTableId: !Ref PrivateRouteTable1
DestinationCidrBlock: 0.0.0.0/0
NatGatewayId: !Ref NatGateway1
DefaultPrivateRoute1將有一個隱含DependsOn的PrivateRouteTable1 和NatGateway1。
因此,唯一需要添加 aDependsOn的情況是沒有直接關系,但需要創建順序。這是一個例子:
InternetGateway:
Type: AWS::EC2::InternetGateway
Properties:
Tags:
- Key: Name
Value: !Ref EnvironmentName
NatGateway1EIP:
Type: AWS::EC2::EIP
DependsOn: InternetGatewayAttachment
Properties:
Domain: vpc
在這種情況下,DependsOn在彈性 IP 地址和 InternetGateway 之間定義了 a。這很有幫助,因為彈性 IP 地址和 Internet 網關(鏈接到 VPC)之間沒有直接關系。
我見過 Amazon EC2 實體在其用戶資料腳本中出現故障的情況,因為其他資源尚未“準備好”,因此該腳本無法訪問 Internet。診斷此類情況可能很困難,因為它們可能是暫時的。因此,您可能希望DependsOn在所需資源之間沒有直接參考的情況下專門添加一些參考。
轉載請註明出處,本文鏈接:https://www.uj5u.com/yidong/420356.html
標籤:
