Designing Private Access to AWS Services with VPC Endpoints
This lesson explains how VPC endpoints keep traffic from private subnets to AWS services and SaaS providers on the AWS network, remove the need for internet egress and give a point at which access can be restricted by policy.
Learning outcomes
After completing this lesson, you will be able to:
- Distinguish gateway from interface endpoints.
- Restrict endpoints with endpoint policies.
- Explain how centralised interface endpoints scale across many VPCs.
Gateway and interface endpoints
VPC endpoints give private access to AWS services, and the two types differ in reach and cost. A gateway endpoint serves only S3 and DynamoDB. It is a route table entry that sends traffic for the service's prefix list to the endpoint, and it is free. It works only for traffic originating in that VPC, so it cannot be used from on premises or from peered VPCs, and security groups do not apply to it.
An interface endpoint, powered by PrivateLink, serves most AWS services, SaaS providers and your own endpoint services. It creates network interfaces with private IP addresses in your subnets, so it can be reached from on premises over VPN or Direct Connect and from peered VPCs, and security groups control access to it. It is charged per hour in each Availability Zone and per gigabyte processed. The following table summarises the differences.
Endpoint policies
An endpoint policy is a resource policy on a VPC endpoint that limits what can be reached through it, and combined with organisation condition keys it enforces part of the data perimeter at the network edge. The condition aws:ResourceOrgID limits access to resources owned by the organisation, so a compromised instance cannot upload data to an attacker's bucket through the endpoint. The condition aws:PrincipalOrgID limits access to the organisation's own principals, so credentials stolen from another organisation cannot be used through it.
The control works in the other direction as well: bucket and key policies can require aws:SourceVpce, so the resource is reachable only through named endpoints, which keeps data inside the network even for principals that hold valid permissions.
Designing endpoints at scale
Gateway endpoints for S3 and DynamoDB are free and remove NAT gateway processing charges for that traffic, so every VPC should have them. Interface endpoints are charged per Availability Zone, so creating the same twenty endpoints in hundreds of VPCs multiplies cost. The usual design centralises interface endpoints in a shared services VPC reached through a transit gateway, with Route 53 private hosted zones, or Route 53 Profiles, shared to the spoke VPCs so that service names resolve to the central endpoints.
PrivateLink endpoints to SaaS providers that offer endpoint services replace internet connections to those providers. On-premises clients reach S3 privately through an S3 interface endpoint over Direct Connect or VPN, because a gateway endpoint works only for traffic that starts inside its VPC.
An S3 endpoint that only reaches company buckets
Workloads in a data-processing VPC must use S3, but compromised code must not be able to upload data to an attacker's bucket. The S3 gateway endpoint carries a policy that allows only buckets owned by the organisation:
{
"Version": "2012-10-17",
"Statement": [{
"Sid": "OnlyOrgBuckets",
"Effect": "Allow",
"Principal": "*",
"Action": "s3:*",
"Resource": "*",
"Condition": { "StringEquals": { "aws:ResourceOrgID": "o-a1b2c3d4e5" } }
}]
}Because the VPC has no NAT gateway, the endpoint is the only path to S3, so the policy is a hard boundary. In the other direction, the company's sensitive buckets require aws:SourceVpce to match this endpoint, so they cannot be read from anywhere else. Interface endpoints for STS, KMS and Secrets Manager are created in a shared services VPC and reached by spoke VPCs through the transit gateway, with private hosted zones shared through a Route 53 Profile, which avoids paying for the same endpoints in each of 30 VPCs.
Can an endpoint policy grant access that IAM policies do not?
Show answer
No. An endpoint policy only narrows which principals, actions and resources can be used through the endpoint; the request still needs permission from the identity and resource policies.
Exam Tips
Remember for the exam
- S3 and DynamoDB gateway endpoints are free; interface endpoints are charged.
- To restrict a VPC endpoint to your organisation's resources, use an endpoint policy with aws:ResourceOrgID.
- To make a bucket reachable only through your endpoint, require aws:SourceVpce in its policy.
- Centralise interface endpoints in a shared services VPC to reduce cost across many VPCs.
- On-premises access to S3 over Direct Connect needs an S3 interface endpoint.