是否可以重用 cloudformation 模板中的现有路由表

问题描述

我正在写一个 cft 来连接 dynamodb uisng vpcEndpoint。

      DynamoDBEndpoint:
        Type: "AWS::EC2::VPCEndpoint"
        Properties:
          RouteTableIds:
            - !Ref PublicRouteTable
            - !Ref Private0RouteTable
            - !Ref Private1RouteTable
            - !Ref Private2RouteTable
          ServiceName:
            !Sub "com.amazonaws.${AWS::Region}.dynamodb"
          VpcId: !Ref VPC

Parameters:
  vpcId:
    Description: Choose the existing one
    Type: AWS::EC2::VPC::Id

我通过使用参数获取现有的 vpcId,有什么办法可以利用我现有的路由表,请建议我如何定义这个引用 PublicRouteTable 和引用 PrivateRouteTable。

解决方法

您的参数 vpcId 有效,因为它使用 AWS::EC2::VPC::Id 类型,该类型属于 CloudFormation 中的 Supported AWS-specific parameter types

遗憾的是,CloudFormation does not support 路由表的类型类似。指定参数时,您必须在控制台中手动输入路由表 ID。