Home AWSAWS VPC Endpoints: Reach S3 Privately Without a NAT Gateway

AWS VPC Endpoints: Reach S3 Privately Without a NAT Gateway

by Knowledge Base Linux
Clean technical illustration of aws vpc endpoints connecting a private VPC subnet to Amazon S3 over a private network path, no text in image

Every private subnet in a VPC eventually needs to talk to Amazon S3. Application servers download deployment artifacts, batch jobs read input data, and backup scripts push archives to a bucket. By default, that traffic leaves the VPC through a NAT gateway or an internet gateway and crosses the public internet, even though both the instance and the bucket belong to AWS. AWS VPC endpoints remove that detour: they give resources inside a VPC a private path to supported AWS services, so S3 traffic never leaves the Amazon network.

Clean technical illustration of aws vpc endpoints route table directing S3 traffic through a gateway endpoint, no text in image

This guide explains how AWS VPC endpoints work, walks through creating a gateway endpoint for S3, shows how to lock it down with a least-privilege endpoint policy, and covers verification and troubleshooting. You will also learn when an interface endpoint is the better choice, so you do not pay for more than you need.

Why AWS VPC Endpoints Matter

There are two practical reasons to keep S3 traffic private. The first is security. Traffic that never traverses the public internet has a smaller attack surface, and you can enforce at the network level that S3 is reachable only from your VPC. Combined with a bucket policy that denies requests not coming through your endpoint, you get a strong guarantee about where data can flow.

The second reason is cost. A NAT gateway costs an hourly fee plus a per-gigabyte data-processing charge for every byte it forwards, including traffic to S3. If your workloads move gigabytes of data to and from S3 every day, that processing fee adds up quickly. A gateway endpoint for S3, by contrast, is free. There is no hourly charge and no per-gigabyte processing fee, so replacing the NAT path with a gateway endpoint can cut a noticeable line item from your bill.

There is a third benefit that matters for compliance. In short, AWS VPC endpoints turn S3 access from a public-internet dependency into a private, auditable network path. Many security frameworks ask you to demonstrate that sensitive data does not cross public networks. A gateway endpoint, together with route tables and endpoint policies, gives you a clean, auditable answer to that question.

How AWS VPC Endpoints Work

AWS offers two kinds of VPC endpoints, and choosing the right one matters.

Gateway endpoints

A gateway endpoint is available for Amazon S3 and DynamoDB only. It works by adding a route to your VPC route tables: the prefix list for the service (for example, the S3 prefix list for your region) points at the endpoint instead of at the NAT gateway or internet gateway. Traffic matching that prefix list is routed privately within the AWS network. There is no elastic network interface and no hourly charge.

One important detail: a gateway endpoint is associated with route tables, not with subnets directly. A subnet uses the endpoint only if the route table it is associated with includes the endpoint route. Forgetting this association is the most common reason a gateway endpoint appears to do nothing.

Interface endpoints

An interface endpoint uses AWS PrivateLink. AWS provisions one or more elastic network interfaces inside your subnets, each with a private IP address, and DNS names for the service resolve to those private addresses. Interface endpoints support most AWS services, including S3, and they work for traffic coming from on-premises networks over Direct Connect or a VPN.

Interface endpoints cost an hourly fee per availability zone plus a data-processing charge, so they are not free the way gateway endpoints are. For S3, the usual rule is simple: use a gateway endpoint when your traffic originates inside the VPC, and consider an interface endpoint only when you need private DNS resolution, on-premises access, or an endpoint policy enforced at the interface level that a gateway endpoint cannot provide. Many architectures use both: a gateway endpoint for in-VPC traffic and an interface endpoint for on-premises clients.

Prerequisites

  • An AWS account with a VPC that has at least one private subnet (no route to an internet gateway).
  • An EC2 instance in that private subnet for testing, with the AWS CLI installed and an IAM role that allows S3 access.
  • An S3 bucket in the same region as the VPC. Gateway endpoints are regional, so the endpoint and the bucket must be in the same region.
  • AWS CLI v2 configured with credentials that can manage VPC endpoints, or access to the VPC console.
  • The ID of the route table used by your private subnet, and the ID of your VPC.

If you are still getting comfortable with VPC building blocks, start with our guide to Amazon VPC basics: subnets, route tables, and security groups before continuing.

Creating AWS VPC Endpoints for S3

Creating one of your AWS VPC endpoints for S3 takes one command. Replace the placeholder IDs with your own, and choose the service name for your region. For the us-east-1 region, the service name is com.amazonaws.us-east-1.s3; other regions follow the same pattern.

aws ec2 create-vpc-endpoint \
  --vpc-id vpc-0123456789abcdef0 \
  --service-name com.amazonaws.us-east-1.s3 \
  --route-table-ids rtb-0123456789abcdef0 \
  --vpc-endpoint-type Gateway

To find the correct service name for your region, list the available services and filter for S3:

aws ec2 describe-vpc-endpoint-services \
  --filters Name=service-name,Values=*s3* \
  --query "ServiceDetails[].ServiceName" \
  --output table

After creation, inspect the route table. You should see a new route whose destination is the S3 prefix list (shown as pl-xxxxxxxx) and whose target is the new endpoint ID (shown as vpce-xxxxxxxx).

aws ec2 describe-route-tables \
  --route-table-ids rtb-0123456789abcdef0 \
  --query "RouteTables[].Routes[]"

You can also create the endpoint in the console: open VPC, choose Endpoints, click Create endpoint, select the AWS service for S3 with type Gateway, pick your VPC, and select the route tables used by your private subnets. The effect is identical.

Locking Down the Endpoint with a Least-Privilege Policy

By default, a gateway endpoint allows full access to S3, which means any instance in the associated subnets can reach any bucket its IAM permissions allow. That is too broad for most environments. An endpoint policy controls which buckets and actions the endpoint permits, and it works together with IAM policies and bucket policies: a request must be allowed by all three layers.

The following policy allows GetObject and PutObject only on a single bucket, and only for principals in your own account. Adjust the bucket name and account ID before applying it.

{
  "Statement": [
    {
      "Sid": "AllowOnlyAppBucket",
      "Principal": "*",
      "Action": [
        "s3:GetObject",
        "s3:PutObject"
      ],
      "Effect": "Allow",
      "Resource": [
        "arn:aws:s3:::my-app-bucket",
        "arn:aws:s3:::my-app-bucket/*"
      ],
      "Condition": {
        "StringEquals": {
          "aws:PrincipalAccount": "123456789012"
        }
      }
    }
  ]
}

Apply the policy when you create the endpoint with the --policy-document flag, or update an existing endpoint with modify-vpc-endpoint. Then, for defense in depth, add a bucket policy condition that denies requests unless they arrive through your endpoint, using the aws:sourceVpce condition key with your endpoint ID. With both layers in place, data can neither leave through another path nor be pulled from outside the VPC.

Verifying Private S3 Access

Once your AWS VPC endpoints are created, verification has three parts: routing, DNS behavior, and an actual S3 request.

First, confirm the route table. The S3 prefix list route must point at the endpoint, and the private subnet must use that route table. If the subnet uses a different route table, associate the endpoint with that table instead.

Second, check name resolution. Gateway endpoints do not change DNS: S3 hostnames still resolve to public S3 IP addresses, but the route table sends that traffic over the private endpoint path because the prefix list covers those addresses. This surprises many engineers, so do not treat a public-looking resolved address as proof that traffic is leaving the VPC. The route, not the resolved address, decides the path.

Third, test from the private instance. List the bucket and download a test object:

aws s3 ls s3://my-app-bucket/
aws s3 cp s3://my-app-bucket/test.txt /tmp/test.txt

To prove the endpoint policy works, try an action it denies, such as listing a different bucket, and confirm it fails with an access denied error. A deny test is as important as a success test: an endpoint that allows everything has not been locked down, it has only been created.

If your workloads also serve content from S3 to users, see our guide on how to host a static website on Amazon S3 for the bucket website configuration that pairs with this private access pattern.

Troubleshooting AWS VPC Endpoints

Most problems with AWS VPC endpoints come down to route tables, DNS assumptions, or policy layers. Work through the checks below in order.

Traffic still goes through the NAT gateway

Check the route table association first. The endpoint route exists only in the route tables you selected at creation. If the subnet uses another route table, add the endpoint to it. Also check route priority: a more specific route to the NAT gateway wins over the prefix list route, so remove any overlapping specific routes for S3 address ranges.

Access denied after adding an endpoint policy

Endpoint policies are an additional deny layer. A request that IAM allows can still be blocked by the endpoint policy, and the error message does not always say which layer denied it. Test with a permissive policy first, confirm access works, then tighten the policy one statement at a time. Check the resource ARNs carefully: forgetting the /* object ARN blocks object operations while allowing bucket-level calls.

S3 works from some subnets but not others

This is almost always a route table mismatch. Each subnet uses exactly one route table, and only associated route tables carry the endpoint route. Audit every private subnet’s route table association, not just the one you tested from.

Cross-region bucket access fails

Gateway endpoints are regional. An endpoint in us-east-1 does not provide a private path to a bucket in eu-west-1. Either keep the bucket in the endpoint’s region or accept that cross-region traffic follows the normal internet or NAT path, and design your data placement accordingly.

Conclusion

AWS VPC endpoints are one of the simplest high-value networking changes you can make in a VPC. A gateway endpoint for S3 costs nothing, removes NAT data-processing charges for S3 traffic, and keeps that traffic off the public internet. The work is in the details: associate the right route tables, write a least-privilege endpoint policy, add a matching bucket policy condition, and verify with both a success test and a deny test.

Start with S3, measure the drop in NAT data-processing charges over the next billing cycle, and then apply the same pattern to DynamoDB. For services beyond those two, evaluate interface endpoints against their hourly cost and use them where private DNS or on-premises access genuinely requires PrivateLink. For the authoritative reference on endpoint types, policies, and limits, see the Amazon VPC endpoints documentation.

You may also like

KbLinux

Typically replies within a day

Hello, Welcome to the site. Please click below button for chatting me through Telegram.