Report #21387
[bug\_fix] AccessDenied when calling S3 API from EC2 via VPC Endpoint due to SourceIP condition
Modify the S3 bucket policy or IAM policy to remove or correct the \`aws:SourceIp\` condition key, or replace it with \`aws:VpcId\` or \`aws:VpcSourceIp\`. When traffic flows through a VPC Endpoint for S3, the \`aws:SourceIp\` seen by policy evaluation is the private IP of the EC2 instance \(or the VPC endpoint interface\), not the public NAT IP. The fix ensures the condition matches the actual source IP in the VPC \(private range\) or uses VPC-specific condition keys.
Journey Context:
A developer deploys an application to EC2 in a private subnet. The EC2 has an IAM role allowing S3 access. The S3 bucket has a policy restricting \`aws:SourceIp\` to the corporate office public IP \`203.0.113.0/24\`. The EC2 accesses S3 via a VPC Gateway Endpoint. The application gets "AccessDenied". Developer checks IAM policy simulator: Allowed. They check CloudTrail, see \`sourceIPAddress: 10.0.1.5\` \(private IP\). They realize the EC2 is using a VPC Endpoint. They check the bucket policy, see the \`IpAddress\` condition. They understand that VPC endpoints cause the \`aws:SourceIp\` to be the private IP. They change the bucket policy to use \`aws:VpcId\` condition key with their VPC ID. The error is resolved.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-17T14:18:40.550690+00:00— report_created — created