Creating VPC endpoint service with AWS PrivateLink
3 min readSep 23, 2020
Prerequisites for demo:
- Two VPCs: Default ( 172.31.0.0/16) and Custom( e.g. create with CIDR 10.0.0.0/16 for demo)
- Jumpbox/Bastion instance in public subnet of Default VPC ( Security Group: SSH access at port 22 from public internet(0.0.0.0/0)
- Instance in private subnet of Default VPC ( Security Group : Allows access for SSH only from SG of Bastion host in public subnet)
- Network Load Balancer in public subnet of Custom VPC ( keep this internet facing with Listners on TCP port 80)
- Instance having a webpage ( at /var/www/html > index.html with some basic HTML page for this demo) in private subnet of Custom VPC ( Security Group : Allow access only from the Private IP of the Network Load Balancer mentioned above for SSH and HTTP( to pass the health check). You can get the private IP of NLB from the Network Interfaces tab from VPC side pane. Just write your NLB name in filter and it will show you private IP of all NLB nodes according the AZ wise spread.
- NLB attached to the target group having instances from private subnet of custom VPC.
NOTE: You should also have route tables properly set up for this.
Route table associated with public subnet default vpc should be like:
Route table associated with private subnet default vpc should be like:
Route table associated with private subnet custom vpc should be like:
If you have all this things ready then let’s set the VPC endpoint using AWS PrivateLink
- Go to Endpoint Services from VPC console.
- Click create endpoint service
- Select NLB you created. It will show you the AZ in which your NLB is spreaded in Included Availablity zone
- Keep Require Acceptance for Endpoint checked.
- Click Create Service. Copy the service name of this, will be required
- Now go to Endpoints from VPC console
- Click create endpoint > Find service by name > Copy the service name URL which you copied in point 5 > Click verify. Once done successfully you are good to go
- Keep default VPC and choose the subnets below. You will only be able to select those which are configured for NLB too. But change the subnet to private ones
- Now associate a SG which allows SSH traffic only from Custom VPC CIDR ( i.e. 10.0.0.0/16 here)
- Click create endpoint
- Now go to Endpoint service > Endpoint Connection tab. One pending request might be there. Accept that request by going into actions and Accepting it.
- Once done you have successfully configured your VPC endpoint private link
- To verify lets do a test:
- SSH to Bastion > Instance in private subnet of default VPC > curl < DNS name of the endpoint created in step 10.>. If you are successfully able to see your webpage then you have successfully configured private link.