31
votes

I'm trying to copy a file from a private s3-bucket via cli to my ec2 instance. The ec2 is in the same region as the bucket and has the following IAM role attached (AmazonS3FullAccess):

{
"Version": "2012-10-17",
"Statement": [
   {
     "Effect": "Allow",
     "Action": "s3:*",
     "Resource": "*"
   }
 ]
}

But the command aws s3 cp s3://[BUCKETNAME]/index.html fails with the error:

A client error (400) occurred when calling the HeadObject operation: Bad Request Completed 1 part(s) with ... file(s) remaining.

I already double checked the spelling of the bucket name...

5
Is that the full cp command line you were running? cp also needs an argument for the local path name. - Karen B
sorry i forgot this part in the posting, but it was there: ' aws s3 cp s3://[bucketname]/index.html /var/www/html/ ' - shootoke

5 Answers

40
votes

I added the --region option to the statement and everything is working now:

aws s3 cp s3:/[BUCKETNAME]/ . --recursive --region [REGION]
18
votes

This error also happens when your session has expired if using temporary security credentials with an assumed role. Not a forbidden or unknown id as you would expect.

6
votes

The --region parameter did not work for me.

I tried using --profile, and it worked all fine.

aws s3api head-bucket --bucket xxxx --profile dev-profile
5
votes

My problem got fixed as soon as I upgraded to the latest version of aws cli. Here is how you upgrade : pip install --upgrade --user awscli

specifying the region wasn't helpful

0
votes

When I changed my same policy from "inline policies" to "managed policies" it worked. Ref my answer at https://stackoverflow.com/a/37532132/4126114