dis*_*ing 1 amazon-web-services aws-cloudformation infrastructure-as-code
在 CloudFormation 中使用 Depends On 的最佳实践是什么?我相信从我读到的内容来看,不建议在 Azure 中这样做并尽量减少它的使用。
例如,我想在 ASG 策略和 ASG 组之间建立 DependsOn 关系。
在上图中,您可以看到 ASG Policy 有一个字段AutoScalingGroupName。
因此,ASG 策略取决于 AutoScaling 组的创建。
这两者之间是否存在依赖关系?
一般来说,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
Run Code Online (Sandbox Code Playgroud)
DefaultPrivateRoute1将有一个隐含的DependsOn和。PrivateRouteTable1 NatGateway1
因此,唯一特别需要添加 a 的情况DependsOn是没有直接关系,但需要创建顺序时。这是一个例子:
InternetGateway:
Type: AWS::EC2::InternetGateway
Properties:
Tags:
- Key: Name
Value: !Ref EnvironmentName
NatGateway1EIP:
Type: AWS::EC2::EIP
DependsOn: InternetGatewayAttachment
Properties:
Domain: vpc
Run Code Online (Sandbox Code Playgroud)
在本例中,DependsOn在弹性 IP 地址和 Internet 网关之间定义了 a。这很有用,因为弹性 IP 地址和互联网网关(链接到 VPC)之间没有直接关系。
我曾见过 Amazon EC2 实例在其用户数据脚本中出现故障的情况,因为其他资源未“就绪”,因此该脚本无法访问 Internet。诊断此类情况可能很困难,因为它们可能是暂时的。因此,您可能需要专门添加一些DependsOn所需资源之间没有直接引用的引用。
| 归档时间: |
|
| 查看次数: |
2592 次 |
| 最近记录: |