How do you restrict an S3 bucket so it is reachable only from your VPC?
IntermediateScenarioVPC and Networking
Answer
Situation read → Combine a gateway endpoint with a bucket policy condition.
What I'd do →
- Add a Deny statement with
StringNotEqualsonaws:SourceVpceequal tovpce-0abc - Keep an exception for admin roles or the console flow
- Test from inside and outside the VPC
- Don't lock out CloudFormation or other AWS service principals
Why → A deny-unless-endpoint policy blocks leaked credentials used from outside.
Interview tip → Mention the risk of locking out yourself; test with a break-glass role.
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