amazon-web-services - 在 CloudFormation 中跨不同 AWS 账户添加 VPC 对等路由

标签 amazon-web-services aws-cloudformation amazon-vpc

使用这个AWS walkthrough ,我可以在不同的 aws 账户之间成功添加 vpc 对等连接。

连接会自动接受,因为接受者账户中的 IAM 角色设置已被授予该权限,并在请求连接时在请求者账户中被引用。

这一切都很好,但是两个 VPC 中没有路由表条目,此连接就没有意义。

查看示例中的第二个模板;创建 AWS::EC2::VPCPeeringConnection 的那个,有没有办法在第一个模板中创建的 VPC 的路由表条目中添加路由?

我当然可以将路由表id传递给第二个模板,但我认为这还不够。我认为帐户之间必须存在额外的信任关系才能实现这一点。

知道如何做到这一点吗?

最佳答案

可以从第二个模板中在第一个 VPC 中创建路由表条目。您可以在第二个模板中包含的相关 CloudFormation 资源示例:

Resources:
  IsolationVPC:
    Type: AWS::EC2::VPC
    Properties:
      CidrBlock: "10.1.0.0/16"

  PrimaryPrivateSubnet:
    DependsOn:
      - IsolationVPC
    Type: AWS::EC2::Subnet
    Properties:
      VpcId:
        Ref: IsolationVPC
      AvailabilityZone: ${self:provider.region}a
      CidrBlock: 10.1.1.0/24
  PrimaryPrivateSubnetRouteTable:
    Type: AWS::EC2::RouteTable
    Properties:
      VpcId:
        Ref: IsolationVPC
    DependsOn:
      - IsolationVPC

  PrimaryPublicSubnet:
    DependsOn:
      - IsolationVPC
    Type: AWS::EC2::Subnet
    Properties:
      VpcId:
        Ref: IsolationVPC
      AvailabilityZone: ${self:provider.region}a
      CidrBlock: 10.1.2.0/24
  PrimaryPublicSubnetRouteTable:
    Type: AWS::EC2::RouteTable
    Properties:
      VpcId:
        Ref: IsolationVPC
    DependsOn:
      - IsolationVPC

  PeeringConnection:
    Type: AWS::EC2::VPCPeeringConnection
    DependsOn:
      - IsolationVPC
    Properties: 
      PeerVpcId: <first VPC ID goes here>
      VpcId:
        Ref: IsolationVPC
  PublicRoutingTableEntry:
    Type: AWS::EC2::Route
    DependsOn:
      - PrimaryPublicSubnetRouteTable
      - PeeringConnection
    Properties:
      RouteTableId:
        Ref: PrimaryPublicSubnetRouteTable
      DestinationCidrBlock: <first VPC CIDR block goes here>
      VpcPeeringConnectionId:
        Ref: PeeringConnection
  PrivateRoutingTableEntry:
    Type: AWS::EC2::Route
    DependsOn:
      - PrimaryPrivateSubnetRouteTable
      - PeeringConnection
    Properties:
      RouteTableId:
        Ref: PrimaryPrivateSubnetRouteTable
      DestinationCidrBlock: <first VPC CIDR block goes here>
      VpcPeeringConnectionId:
        Ref: PeeringConnection
  ReversePublicRoutingTableEntry:
    Type: AWS::EC2::Route
    DependsOn:
      - PeeringConnection
    Properties:
      RouteTableId: <first VPC public route table ID goes here>
      DestinationCidrBlock: 10.1.0.0/16
      VpcPeeringConnectionId:
        Ref: PeeringConnection
  ReversePrivateRoutingTableEntry:
    Type: AWS::EC2::Route
    DependsOn:
      - PeeringConnection
    Properties:
      RouteTableId: <first VPC private route table ID goes here>
      DestinationCidrBlock: 10.1.0.0/16
      VpcPeeringConnectionId:
        Ref: PeeringConnection

直到我阅读此处提供的示例时我才意识到这一点:https://github.com/lizduke/cloudformationexamples但后来测试成功。

关于amazon-web-services - 在 CloudFormation 中跨不同 AWS 账户添加 VPC 对等路由,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48932117/

相关文章:

python - Django 应用找不到环境变量

php - 通过 PHP 将 EC2 连接到 RDS

ubuntu - 连接到托管 Chef 的 Cloudformation 片段

amazon-web-services - AWS Cloudformation 参数依赖性

amazon-web-services - 如何在 AWS 账户与外部服务或应用程序(不在 AWS 上)之间建立连接

django - 如何解决拒绝访问 aws s3 文件?

amazon-s3 - 使用pull方法的跨账户codepipeline

python - 自动检查并从 CloudFormation 模板中删除资源 #20611

amazon-web-services - 如何将对现有 VPC 的引用传递给 cloudformation 模板?

amazon-web-services - 在嵌套堆栈中将参数从父堆栈传递到子堆栈 - Cloudformation