如何在自定义 CloudFormation 资源中指定依赖项?
How to specify dependencies in Custom CloudFormation resources?
创建自定义 CloudFormation 资源实现时,创建的资源稍后可用于 "add" 更多依赖其自身的子资源。
例如:
ResourceA:
Type: Custom::Parent
ResourceB:
Type: Custom::Child
Properties:
Parent: !Ref ResourceA
仅将 DependsOn
添加到 ResourceB
是否足以确保它在 ResourceA
收到 Delete
请求之前被删除?像这样 -
ResourceB:
DependsOn: ResourceA
Type: Custom::Child
Properties:
Parent: !Ref ResourceA
或者是否会出现 ResourceA
收到 Delete
请求并在 ResourceB
完成删除过程之前失败的情况?
在这种情况下,您甚至不需要 DependsOn
。由于您在 B 的属性中引用了 A,因此 cloudformation 知道 B 对 A 具有依赖性,并且只会在创建 A 时才开始创建 B。
对于删除,相反的情况发生:首先删除 B,然后删除 A。
Cloudformation 只有在没有其他资源依赖它时才会删除资源。
创建自定义 CloudFormation 资源实现时,创建的资源稍后可用于 "add" 更多依赖其自身的子资源。
例如:
ResourceA:
Type: Custom::Parent
ResourceB:
Type: Custom::Child
Properties:
Parent: !Ref ResourceA
仅将 DependsOn
添加到 ResourceB
是否足以确保它在 ResourceA
收到 Delete
请求之前被删除?像这样 -
ResourceB:
DependsOn: ResourceA
Type: Custom::Child
Properties:
Parent: !Ref ResourceA
或者是否会出现 ResourceA
收到 Delete
请求并在 ResourceB
完成删除过程之前失败的情况?
在这种情况下,您甚至不需要 DependsOn
。由于您在 B 的属性中引用了 A,因此 cloudformation 知道 B 对 A 具有依赖性,并且只会在创建 A 时才开始创建 B。
对于删除,相反的情况发生:首先删除 B,然后删除 A。
Cloudformation 只有在没有其他资源依赖它时才会删除资源。