54

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 /var/www/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...

2
  • Is that the full cp command line you were running? cp also needs an argument for the local path name.
    – Karen B
    Commented May 28, 2016 at 2:59
  • sorry i forgot this part in the posting, but it was there: ' aws s3 cp s3://[bucketname]/index.html /var/www/html/ '
    – shootoke
    Commented May 28, 2016 at 7:20

6 Answers 6

48

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

aws s3 cp s3:/[BUCKETNAME]/ . --recursive --region [REGION]
1
  • you can add the Default region when running aws configure
    – chavy
    Commented Mar 17, 2023 at 9:53
48

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.

0
9

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

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

For me, the problem was that I had use_accelerate_endpoint set to true in my AWS config file (~/.aws/config). Changing it to false fixed the issue. This is what my config file looks like now:

[default]
region = us-west-2
output = json
s3 =
    use_accelerate_endpoint = false
-1

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

6
  • My bad. I meant "inline" to "managed". Will edit. Blame it on programming late at night
    – Shadi
    Commented May 31, 2016 at 5:53
  • What's your output for aws --version? Mine is aws-cli/1.10.16 Python/2.7.3 Linux/3.13.0-86-generic botocore/1.4.7
    – Shadi
    Commented May 31, 2016 at 11:19
  • Mine is: aws-cli/1.10.8 Python/2.7.10 Linux/4.4.10-22.54.amzn1.x86_64 botocore/1.3.30
    – shootoke
    Commented May 31, 2016 at 13:35
  • if i run the cp command with the option --region it works. Strange because the bucket as well as the ec2 instance remain to the same region. I'm confused...
    – shootoke
    Commented Jun 1, 2016 at 19:46
  • Looks like your awscli configuration is missing the AWS_DEFAULT_REGION parameter. Check here. You can try using aws configure as described here and here. Otherwise you can just upgrade your awscli with pip install --upgrade awscli to the most recent version.
    – Shadi
    Commented Jun 2, 2016 at 5:35

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.