본문 바로가기

IT 엔지니어/CLOUD

AWS - VPC Peering

[YAML]

  VPCPeeringConnection:
    Type: AWS::EC2::VPCPeeringConnection
    Properties:
      PeerVpcId: !Ref MyVPC2
      VpcID: !Ref MyVPC
      PeerRegion: 'ap-northeast-2'
      Tags:
        - Key : Name
          Value : 'peering'
  
  VPC1ToVPC2Route:
   Type: AWS::EC2::Route
   Properties:
    RouteTableId: !Ref MyPublicRouting1
    DestinationCidrBlock: 172.16.0.0/16
    VpcPeeringConnectionId: !Ref VPCPeeringConnection
 
  VPC2ToVPC1Route:
   Type: AWS::EC2::Route
   Properties:
    RouteTableId: !Ref MyPublicRouting2
    DestinationCidrBlock: 10.0.1.0/16
    VpcPeeringConnectionId: !Ref VPCPeeringConnection

[JSON]

cloudformation = imageid
terraform = ami
# VPC Peering Connection
resource "aws_vpc_peering_connection" "peer" {
  vpc_id        = aws_vpc.vpc1.id
  peer_vpc_id   = aws_vpc.vpc2.id
  auto_accept   = true

  tags = {
    Name = "VPC1-VPC2-Peering"
  }
}

# VPC1 route to VPC2
resource "aws_route" "vpc1_to_vpc2" {
  route_table_id            = aws_route_table.rt1.id
  destination_cidr_block    = aws_vpc.vpc2.cidr_block
  vpc_peering_connection_id = aws_vpc_peering_connection.peer.id
}

# VPC2 route to VPC1
resource "aws_route" "vpc2_to_vpc1" {
  route_table_id            = aws_route_table.rt2.id
  destination_cidr_block    = aws_vpc.vpc1.cidr_block
  vpc_peering_connection_id = aws_vpc_peering_connection.peer.id
}

 

 

요청자 / 수락자 설정
요청 수락
설정 확인
피어링 연결 / 요청자 -> 수락자 / 수락자 -> 요청자 각각 연결 필요

 

 

 

다른 네트워크 이기에

다른 VPC에 속해있는 각각의 인스턴스 간  통신되지 않는다.

 

 

VPC Peering으로 각각 연결 시 통신 확인 가능하다.

 

Peering 연결 시 바로 통신 가능함을 확인

'IT 엔지니어 > CLOUD' 카테고리의 다른 글

AWS - Route53  (0) 2025.06.17
AWS - Transit GW  (0) 2025.06.16
AWS -NLB  (0) 2025.06.14
AWS - ALB  (0) 2025.06.13
AWS - troubleshooting  (0) 2025.06.12