[英]DependsOn best practices in AWS Cloud Formation (example included)
通常,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
。
因此,唯一需要添加DependsOn
的情況是沒有直接關系,但需要創建順序。 這是一個例子:
InternetGateway:
Type: AWS::EC2::InternetGateway
Properties:
Tags:
- Key: Name
Value: !Ref EnvironmentName
NatGateway1EIP:
Type: AWS::EC2::EIP
DependsOn: InternetGatewayAttachment
Properties:
Domain: vpc
在這種情況下,在彈性 IP 地址和 InternetGateway 之間定義了一個DependsOn
。 這很有幫助,因為彈性 IP 地址和 Internet 網關(鏈接到 VPC)之間沒有直接關系。
我見過 Amazon EC2 實例在其用戶數據腳本中出現故障的情況,因為其他資源尚未“准備好”,因此該腳本無法訪問 Internet。 診斷此類情況可能很困難,因為它們可能是暫時的。 因此,您可能希望在所需資源之間沒有直接引用的情況下專門添加一些DependsOn
引用。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.