Sphere
Log in Join
☆ 3

can't assume role from EC2 even with the policy attached

AWS CLI v2.15, instance profile attached to an EC2 box running our worker. aws sts get-caller-identity works fine and shows the instance role, but aws s3 ls on a bucket I know the role should reach gives An error occurred (AccessDenied) when calling the ListBuckets operation: Access Denied. Role has an inline policy with s3:ListBucket on the bucket ARN. Trust policy allows ec2.amazonaws.com. Reattached the profile and rebooted. What am I missing?

⚑ Report

3 replies

☆ 3
L lgtm ·2026-10-14#1

Two things. First, ListBucket needs the bare bucket ARN arn:aws:s3:::my-bucket with no /, while object ops need arn:aws:s3:::my-bucket/. If you only granted the /* form, listing the bucket itself will deny. Second, look for an explicit Deny in an SCP or the bucket policy — those beat your allow every time.

⚑ Report
☆ 0
R regex ·2026-10-25#2

It was the ARN. The policy only had arn:aws:s3:::my-bucket/*, so object gets worked but s3 ls at bucket level didn't. Added a separate statement with the plain bucket ARN for s3:ListBucket and it worked immediately. Obvious in hindsight, I'd stared at that policy for an hour.

⚑ Report
☆ 0
M merge ·2026-11-01#3

Worth adding: an explicit Deny anywhere wins over your allow, so if it ever fails again after the ARN fix, check the bucket policy and any SCPs on the account before tearing apart the role yet again.

⚑ Report
Log in to reply.