Mubasher
Mubasher

Reputation: 950

AWS VPC Peering with private instances of other VPC under auto scaling group

I have successfully created a VPC peering connection between two private instances if I know their private IP addresses. However, I want to achieve a VPC peering for private instances under the auto-scaling group. Please have a look at the following diagram to understand the infrastructure layout.

enter image description here

One of my applications is deployed over a private instance, in VPC B which needs a connection to another application deployed in private instances of VPC A. All the instances are highly scalable due to the Load Balancer and Scaling group.

One way to achieve this connection is a NAT gateway installed in the public subnet of VPC B to request out to the Internet and received by VPC A and routed towards the load balancer. This is a long round trip, and it has more cost. So I want to achieve it by other means like VPC peering but How can I determine the private IP for instances under VPC A at run time?

Or can we use VPC peering to do a connection towards the Loadbalancer of VPC A which can route to any private instance?

Any help is greatly appreciated.

Edit:

Current Configuration: Here is how currently traffic discovers VPC A.

When I call https://www.domainForVPCAPrivateInstance.com/api/healthCheck from any private instance under VPC B, Here is the route It take.

VPC-B: private ec2 -> NAT gateway => internet -> DNS translation -> VPC A: Elastic load blanacer -> to any private instance in VPC A

See Here traffic went through the internet. But VPC peering allows us to communicate between two VPC privately. But for that I have to know the private IP of any instance in VPC A. e.g.

https://private-ip-of-ec2-under-vpc-A/api/healthCheck

Right? But I can't determine. IP of instances when they are under load balancer and auto scaling group. They are highly scalable. So which solution allows to communicate between two VPCs' private instances privately when they are under auto scaling?

Upvotes: 0

Views: 342

Answers (1)

Mark B
Mark B

Reputation: 200682

You could use something like AWS Cloud Map.

Or you could have your code running in VPC B do some sort of lookup using the AWS API, via an AWS SDK, to get the list of instances registered with the load balancer.

Or you could add an Internal load balancer that points to the same targets, and make your requests to that.

Upvotes: 0

Related Questions