amazon-web-services - CloudFormation - Transit Gateway 的路由表路由传播

标签 amazon-web-services aws-cloudformation

我正在使用 CloudFormation 创建以下资源:

  • 专有网络
  • 两个公共(public)子网
  • 两个私有(private)子网
  • 子网的路由表

我已通过我的本地办公室手动创建了站点到站点 VPN。 我已手动创建中转网关并将我的 VPN 连接到它。 现在,由于我将使用 CloudFormation 创建 VPC,因此我想避免手动工作,让 VPC 与 Transit Gateway 相关联,并在 CloudFormation 脚本本身的路由表中传播路由。 请引用以下代码片段:

  VPCTransitGateayAttachment:
    Type: AWS::EC2::TransitGatewayAttachment
    Properties: 
      SubnetIds: 
        - !Ref PrivateSubnet1
        - !Ref PrivateSubnet2
      TransitGatewayId: 'tgw-1234567890'
      VpcId: !Ref VPC

#TransitGateWay Routes
  TransitGateWayPublicRouteTableRoutes:
    Type: AWS::EC2::Route
    Properties:
      RouteTableId: !Ref PublicRouteTable
      DestinationCidrBlock: '0.0.0.0/16'
      TransitGatewayId: 'tgw-1234567890'

  TransitGateWayPrivateRouteTable1Routes:
    Type: AWS::EC2::Route
    Properties:
      RouteTableId: !Ref PrivateRouteTable1
      DestinationCidrBlock: '0.0.0.0/16'
      TransitGatewayId: 'tgw-1234567890'  

  TransitGateWayPrivateRouteTable2Routes:
    Type: AWS::EC2::Route
    Properties:
      RouteTableId: !Ref PrivateRouteTable2
      DestinationCidrBlock: '0.0.0.0/16'
      TransitGatewayId: 'tgw-1234567890'

但是当我执行脚本时遇到以下错误。

The transitGateway ID 'tgw-1234567890' does not exist. (Service: AmazonEC2; Status Code: 400; Error Code: InvalidTransitGatewayID.NotFound; Request ID: 30d31120-f9e2-4870-a378-55bc9a36f5bb)

对于 AWS::EC2::Route 资源。 我不明白是什么问题。 document 说明了 AWS::EC2::Route 的 Transit Gateway 选项。 我还缺少什么?

最佳答案

我在 cloudformation 中遇到了同样的问题,问题是路由必须等待 AWS::EC2::TransitGatewayAttachment,我使用需要 TransitGatewayId 的所有路由运行了 cloudformation 模板参数注释,然后取消注释路线,它起作用了。

documentation这对于互联网网关附件是必需的,但我的测试表明,这对于 TransitGatewayAttachments 也是必需的。

我们应该做的是添加一个 DependsOn ,这应该可以解决问题。

关于amazon-web-services - CloudFormation - Transit Gateway 的路由表路由传播,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/59286839/

相关文章:

amazon-web-services - Docker中的Spring Boot微服务部署

amazon-web-services - 在 AWS 上使用 Lambda 创建内部 API

amazon-web-services - 如何通过 ECS ContainerDefinitions 中的 CloudFormation 从 AWS 参数存储注入(inject)值

java - AWS - Ubuntu 用户 session 停止 Spring Boot 应用程序

javascript - AWS SendRawEmail 与 Meteor

amazon-web-services - 如何创建一个条件,仅允许在同一 CloudFormation 堆栈中创建的资源承担 IAM 角色?

amazon-web-services - cfn-init 指定自定义 json

aws-cloudformation - 如何将 ASG 附加到 ALB 目标组?

amazon-s3 - 在 CloudFormation yaml 中创建 BucketPolicy 时出错

amazon-web-services - AWS ECS 任务定义自动缩放