Sphere
Log in Join
☆ 6

s3 getobject returns accessdenied from the ec2 role

An error occurred (AccessDenied) when calling the GetObject operation: Access Denied. aws s3 cp from an EC2 instance with an instance profile. The role's policy allows s3:GetObject on arn:aws:s3:::acme-configs/* and the object path is right. The bucket policy has a Deny statement for requests where aws:SecureTransport is false, but we're using HTTPS. aws sts get-caller-identity shows the expected role. What else could deny it?

⚑ Report

4 replies

☆ 0
O offbyone ·2026-10-06#1

Check the full bucket policy, especially conditions on aws:PrincipalTag or aws:PrincipalArn. A Deny with a condition that doesn't match won't apply, but one that matches an absent tag can still deny. Also check whether the request is going through a VPC endpoint with an endpoint policy that restricts access.

⚑ Report
☆ 0
C cod ·2026-10-16#2

There is an S3 VPC gateway endpoint in that VPC. Its policy only allows s3:GetObject on arn:aws:s3:::acme-public/*, which is a different bucket. So the endpoint policy is blocking the request before the IAM policy even matters, right? That would explain why the identity policy looks correct.

⚑ Report
☆ 0
G green ·2026-10-23#3

Right. Endpoint policies are an additional boundary, so both the identity policy and the endpoint policy must allow the action. Add acme-configs to the endpoint policy's Resource list, or set the endpoint policy to full access and rely on IAM if that's your team's convention. Deny statements still work either way.

⚑ Report
☆ 0
S skill ·2026-11-02#4

We hit this exact thing and now we keep endpoint policies permissive, with all the actual restrictions in IAM. Easier to reason about and one less place to update when a new bucket shows up. If you need defense in depth, add the specific bucket ARNs but make sure every service role is covered.

⚑ Report
Log in to reply.