CodexBloom - Programming Q&A Platform

AWS S3 sync command over CLI scenarios with 'Access Denied' on specific files despite correct bucket policy

👀 Views: 196 đŸ’Ŧ Answers: 1 📅 Created: 2025-06-02
aws s3 cli bash

I've encountered a strange issue with I'm migrating some code and I've searched everywhere and can't find a clear answer. I'm trying to run the `aws s3 sync` command to sync a local directory with an S3 bucket, but I'm working with an 'Access Denied' behavior for certain files. The command I'm using is: ```bash aws s3 sync ./local-directory s3://my-bucket-name/path/ --exclude "*.tmp" ``` The bucket policy allows the necessary permissions: ```json { "Version": "2012-10-17", "Statement": [ { "Effect": "Allow", "Principal": "*", "Action": "s3:*", "Resource": [ "arn:aws:s3:::my-bucket-name", "arn:aws:s3:::my-bucket-name/*" ] } ] } ``` The question arises for certain files within the local directory, particularly when I try to sync files that are larger than 5MB. I get the behavior message: ``` An behavior occurred (AccessDenied) when calling the PutObject operation: Access Denied ``` I've checked the IAM policy attached to the user running this command, which includes permissions for `s3:PutObject`, `s3:ListBucket`, and `s3:PutObjectAcl` on the bucket. Here's the IAM policy: ```json { "Version": "2012-10-17", "Statement": [ { "Effect": "Allow", "Action": ["s3:PutObject", "s3:ListBucket"], "Resource": [ "arn:aws:s3:::my-bucket-name", "arn:aws:s3:::my-bucket-name/*" ] } ] } ``` I've also verified that the files aren't being encrypted, as the bucket does not enforce encryption. However, the scenario continues, and I need to figure out why these specific files are being blocked. Could there be an scenario with how the AWS CLI handles larger files or is there something else in the configuration that I might be missing? Any insights would be appreciated. My development environment is Ubuntu. How would you solve this? My development environment is Windows. I'm developing on CentOS with Bash. For reference, this is a production web app.