amazon-web-services - 从另一个模板导入 VPCGatewayAttachment

标签 amazon-web-services aws-cloudformation elastic-ip

我有一个包含 InternetGateway 的网络堆栈,它通过 VPCGatewayAttachment 元素连接到 VPC。

我有一个应用程序堆栈,其中有一个 EIP,它应该取决于 VPCGatewayAttachment,当前如下所示:

"MyEIP": {
  "Type": "AWS::EC2::EIP",
  "DependsOn": [
    { "Fn::ImportValue" : {"Fn::Sub": "${NetworkStackName}-GatewayAttachment" } }
  ],
}

但是我收到一个模板错误,指出每个 DependsOn 值都必须是字符串。那么如何导入这个值呢?

最佳答案

您不需要使用DependsOn AWS::EC2::EIP 上的属性应用程序堆栈中的资源,因为 AWS::EC2::VPCGatewayAttachment正在单独的网络堆栈中创建资源。 EIP 资源的 Domain 中对此进行了说明。属性:

Note

If you define an Elastic IP address and associate it with a VPC that is defined in the same template, you must declare a dependency on the VPC-gateway attachment by using the DependsOn attribute on this resource.

当 VPC 在单独的模板中定义时,您无需显式声明任何依赖项。只要应用程序堆栈在网络堆栈之前被删除,EIP 就会在 VPC 网关附加之前被删除。

更一般地说,在堆栈之间声明 DependsOn 是没有必要的。由于如果另一个堆栈引用其输出之一,则无法删除该堆栈,因此使用 Fn::ImportValue 创建跨堆栈引用会创建一个依赖项,即必须先删除包含该引用的堆栈,然后再执行该操作。正在引用堆栈。

关于amazon-web-services - 从另一个模板导入 VPCGatewayAttachment,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40985206/

相关文章:

aws-cloudformation - 在 lambda 存在之前创建 lambda 角色和策略

amazon-web-services - AWS 云信息 : Cross Stack Reference

node.js - 亚马逊AWS Lambda : Cannot find "Request"

amazon-s3 - 我的 s3 存储桶策略不适用于现有或新创建的存储桶

amazon-web-services - 获取 ELB ARN 作为输出

amazon-web-services - 新 IP 仍被禁止使用弹性 IP

android - AWS Android 项目登录

amazon-web-services - AWS EMR 集群无法启动

amazon-web-services - 具有有限弹性IP的AWS架构

amazon-web-services - CloudFormation ElasticIP 参数