Lesson 4 of 4 Amazon VPC

Reaching AWS Services Privately with VPC Endpoints and PrivateLink

This lesson explains how VPC endpoints let resources reach AWS and partner services privately, without internet gateways, NAT or public IP addresses.

Learning outcomes

After completing this lesson, you will be able to:

  • Distinguish gateway endpoints from interface endpoints.
  • Identify the endpoints that fully private subnets need.
  • Explain how endpoint policies restrict access and how PrivateLink exposes services.

Endpoint types

VPC endpoints let resources in a VPC reach AWS services privately, without an internet gateway or NAT gateway, and they come in two types. A gateway endpoint is available only for S3 and DynamoDB. It is a target in the subnets' route tables, so traffic to the service's normal public names travels privately. It is free, which makes it the first choice for private access to those two services, but it works only for traffic originating inside the VPC; it cannot be used from on-premises networks or peered VPCs.

An interface endpoint, powered by AWS PrivateLink, is available for most AWS services, including S3. It creates network interfaces with private IP addresses in chosen subnets, and with private DNS enabled, the service's standard name resolves to them, so applications need no change. Because the endpoint is an address in the VPC, it can also be reached from on-premises networks over VPN or Direct Connect. It is charged per hour in each Availability Zone, plus per gigabyte. The following table summarises the differences.

Gateway endpoint
ServicesS3 and DynamoDB only
HowRoute table target
Reachable fromWithin the VPC only (not on premises or peered VPCs)
CostFree
Interface endpoint (PrivateLink)
ServicesMost AWS services, including S3
HowENIs with private IPs; private DNS resolves the standard name
Reachable fromVPC, and on premises over VPN or Direct Connect
CostPer hour per AZ, plus per GB

The following diagram compares the path each endpoint type provides.

The two types of VPC endpoint. A gateway endpoint, for S3 and DynamoDB only, is a target in route tables and is free, but works only for traffic from inside the VPC. An interface endpoint, powered by PrivateLink, places network interfaces with private IP addresses in chosen subnets for most services; it can be reached from on premises and peered networks, and is charged per hour per AZ and per gigabyte.
S3 supports both types: a gateway endpoint for traffic from the VPC, and an interface endpoint when on-premises networks must also reach it privately.
Sort into groups

Gateway or interface endpoint?

Exam skills 1.2.1 · 4.4.3

Decide which endpoint type each statement describes.

Log in to try this activity Interactive activities are free with an account.

Fully private subnets

In a subnet with no NAT gateway, nothing can reach the public AWS endpoints, so every service the workload calls needs its own VPC endpoint. A missing endpoint shows up as a call that times out. Session Manager, for example, needs three interface endpoints to manage an instance. Pulling container images from ECR needs the two ECR endpoints plus the S3 gateway endpoint, because image layers are stored in S3. Sending logs needs the CloudWatch Logs endpoint. The following table summarises these examples.

NeedEndpoints
Session ManagerSSM, SSM Messages, EC2 Messages
Pulling container imagesECR api and dkr, plus the S3 gateway endpoint
LoggingCloudWatch Logs

In multi-VPC networks, centralise interface endpoints in a shared services VPC reached through a transit gateway with Route 53 private hosted zones.

Troubleshooting scenario

Calls that time out

Exam skills 1.2.1 · 2.1.4

Find the missing endpoint in a subnet with no NAT gateway.

Log in to try this activity Interactive activities are free with an account.

Policies and endpoint services

Access through VPC endpoints can be restricted from both sides. Endpoint policies limit which resources can be reached through an endpoint, for example only the company's own S3 buckets, which prevents data from being copied to an outside bucket. Bucket policies can, in turn, require that requests arrive through a specific endpoint, using the aws:SourceVpce condition, so the bucket cannot be reached from anywhere else.

AWS PrivateLink can also expose a team's own service to other VPCs. An endpoint service, placed behind a Network Load Balancer or Gateway Load Balancer, is consumed through interface endpoints in other VPCs and accounts. Access is one-way, from consumer to service, needs no VPC peering, and works even when the VPCs' CIDR ranges overlap.

True or false

Endpoint policies

Exam skills 1.2.1 · 1.3.6

Check how endpoint and bucket policies restrict private access.

Log in to try this activity Interactive activities are free with an account.
Worked example

A VPC with no internet access at all

A regulated workload must run in subnets with no internet gateway or NAT gateway, yet its Lambda functions and EC2 instances use S3, DynamoDB, Secrets Manager, KMS and CloudWatch Logs.

ServiceEndpoint
Amazon S3Gateway endpoint (free)
Amazon DynamoDBGateway endpoint (free)
AWS Secrets ManagerInterface endpoint
AWS KMSInterface endpoint
CloudWatch LogsInterface endpoint

An endpoint policy on the S3 endpoint allows access only to the company's own buckets, so data cannot be copied to an outside bucket even by compromised code. A partner's SaaS service is reached the same way, through an interface endpoint to the partner's PrivateLink endpoint service.

Check yourself

Which two services can use gateway endpoints?

Show answer

Amazon S3 and DynamoDB. Gateway endpoints add routes to the route table and have no extra charge; other services use interface endpoints.

Exam Tips

Remember for the exam

  • For private access to S3 or DynamoDB at no cost, use a gateway endpoint.
  • To access S3 privately from on premises, use an S3 interface endpoint.
  • To expose a service privately to many consumer VPCs and accounts, use a PrivateLink endpoint service with an NLB.
  • To lock a bucket to traffic from your endpoint, use an aws:SourceVpce condition.
  • When private ECS tasks cannot pull images, add the ECR api and dkr interface endpoints and the S3 gateway endpoint.
  • For Session Manager in subnets without internet, add the SSM, SSM Messages and EC2 Messages interface endpoints.