VPC Endpoints and PrivateLink
Reach S3, DynamoDB and other AWS services privately from your VPC without a NAT Gateway, and expose your own services through PrivateLink.
Intermediate · about 3 hours · difficulty 3/5
Learn first: NAT Gateways, Security Groups and NACLs
By default, a private instance calling S3 goes out through a NAT Gateway to the public S3 endpoint. That costs NAT processing fees and sends traffic over a public path. VPC endpoints fix both.
Gateway endpoints
- Available for S3 and DynamoDB only.
- Added as a route in your route tables.
- Free. Every VPC that uses S3 heavily should have one.
Interface endpoints (PrivateLink)
- Create an elastic network interface with a private IP in your subnets for services like Secrets Manager, ECR, CloudWatch Logs, SSM and STS.
- Private DNS makes the normal service hostname resolve to the private IP, so code does not change.
- Charged per hour per AZ plus per GB, so add them deliberately.
Endpoint policies
Attach a policy to the endpoint to restrict which buckets or actions are reachable through it, and use aws:SourceVpce in bucket policies to accept traffic only from your endpoint. This is a strong data-exfiltration control.
Exposing your own services
With PrivateLink you can publish a service behind a Network Load Balancer and let other VPCs or customers consume it through an interface endpoint, without peering or overlapping-CIDR worries. Azure Private Link and GCP Private Service Connect are the equivalents.
Pitfalls
- Fully private subnets (no NAT) where ECS cannot pull images because ECR, S3 and logs endpoints are missing.
- Forgetting to enable private DNS on interface endpoints.
You are ready to move on when you can run an instance in a subnet with no internet route that still reads from S3 and fetches a secret.
Key concepts
- Gateway endpoints (S3, DynamoDB)
- Interface endpoints
- Private DNS for endpoints
- Endpoint policies
- aws:SourceVpce in bucket policies
- Publishing services with PrivateLink
Mini project
Add a free S3 gateway endpoint to a private subnet with no NAT, attach an instance role, and prove that aws s3 ls works while curl to a public website fails. Use a free-tier instance and Session Manager; terminate it and delete the VPC afterwards.
Check yourself
Which two AWS services support free gateway endpoints, and why do they save money compared with a NAT Gateway?