Home > Mobile >  AWS Cross-Region VPC Peering Cloudformation doesn't recognise the VPC in the other region
AWS Cross-Region VPC Peering Cloudformation doesn't recognise the VPC in the other region

Time:05-25

I have been working on creating a VPC Peering Connection that can peer from eu-west-1 to us-east-1 with the use of a cloudformation. This is the cloudformation as of right now:

AWSTemplateFormatVersion: 2010-09-09
Description: This templates creates a VPC Peering connection. (Requester Account)

Parameters:
  PeerName:
    Description: Name of the VPC Peer
    MaxLength: 255
    Type: String
  PeerVPCID:
    AllowedPattern: '^vpc-[0-9a-f]{17}$'
    ConstraintDescription: Must have a prefix of "vpc-". Followed by 17 characters (numbers, letters "a-f")
    Description: ID of the VPC with which you are creating the VPC peering connection
    Type: AWS::EC2::VPC::Id
  VPCID:
    Description: ID of the VPC
    Type: AWS::EC2::VPC::Id
  PeerRegion:
    Description: Region of the VPC Accepter (not required)
    Type: String

Resources:
  VPCPeeringConnection:
    Type: AWS::EC2::VPCPeeringConnection
    Properties:
      VpcId: !Ref VPCID
      PeerVpcId: !Ref PeerVPCID
      PeerOwnerId: !Ref "AWS::AccountId"
      PeerRegion: !Ref PeerRegion
      Tags:
        - Key: Name
          Value: !Ref PeerName

Outputs:
  VPCPeeringConnectionId:
    Description: VPC Peering Connection ID
    Value: !Ref VPCPeeringConnection

These are the values for the parameters:

PeerName: Connector
PeerVPCID: vpc-1234567
VPCID: vpc-7654321
PeerRegion: us-east-1

I understand that I need an accepter that approves the connection in us-east-1, but the current cloudformation outputs that it doesn't recognise the VPCID to be valid (the one that is in the other region to the AWS account I'm using).

When, I create the VPC Peering Connection in the GUI it throws no errors, I just have to accept the connection and update the route tables, which all work fine... is there something I should be doing with the current cloudformation?

Thanks for any help!

CodePudding user response:

To solve that change:

 Type: AWS::EC2::VPC::Id

into

 Type: String

for the remote VPC, i.e. the VPC from a region other then where you deploy your stack.

  • Related