Traffic from your VPC to S3 goes through the NAT gateway. How do you keep it on the AWS network and add control?
IntermediateScenarioVPC and Networking
Answer
Situation read → A gateway endpoint routes S3 traffic privately and allows policy control at no charge.
What I'd do →
- Create the endpoint:
aws ec2 create-vpc-endpoint --vpc-id vpc-0abc --service-name com.amazonaws.eu-west-1.s3 --route-table-ids rtb-0abc - Attach an endpoint policy restricting access to your buckets
- Add a bucket policy condition
aws:SourceVpceso the bucket is only reachable through the endpoint - Verify with
tracerouteor route table entry for the prefix list
Why → The endpoint adds a prefix-list route that wins over the default route, so NAT is bypassed.
Interview tip → Gateway endpoints exist only for S3 and DynamoDB; everything else uses interface endpoints.
More on VPC and Networking
What is a VPC and what are the CIDR constraints?BeginnerWhat makes a subnet public or private?BeginnerHow do route tables work, including the local route and longest-prefix match?IntermediateInternet Gateway vs NAT Gateway: what does each do?BeginnerNAT Gateway vs NAT instance?IntermediateSecurity group vs network ACL: compare them.Beginner