AYBABTU
AYBABTU

Reputation: 1026

AWS CLI 'cp' fails with "The specified bucket does not exist"

I am doing my first steps with AWS and trying AWS CLI to copy a file from an EC2 server to a S3 server.

I receive an error:

A client error (NoSuchBucket) occurred when calling the PutObject operation: The specified bucket does not exist

My command is as follows:
- I went to my S3 dashboard, selected the bucket -> properties and copeied the 'Endpoint' value which is

[bucket name].s3-website-us-west-2.amazonaws.com

aws s3 cp ./file.ext s3://[bucket name].s3-website-us-west-2.amazonaws.com/file.ext

But it failed with the error described earlier - bucket does not exist.

p.s. Running

aws s3api list-buckets --query 'Buckets[].Name'

Shows that the bucket does exist so that isn't the issue to my understanding.

EDIT If I do not use the endpoint but only use the bucket name the error message encourage to use the full name which in all the online examples seems exactly like the endpoint

upload failed: ./file.ext to s3://[bucket name]/file.ext A client error (PermanentRedirect) occurred when calling the PutObject operation: The bucket you are attempting to access must be addressed using the specified endpoint. Please send all future requests to this endpoint: [bucket name].s3.amazonaws.com You can fix this issue by explicitly providing the correct region location using the --region argument, the AWS_DEFAULT_REGION environment variable, or the region variable in the AWS CLI configuration file. You can get the bucket's location by running "aws s3api get-bucket-location --bucket BUCKET".

Upvotes: 3

Views: 38402

Answers (3)

Piyush Patil
Piyush Patil

Reputation: 14523

You are using the endpoint of the bucket. Do not use that. Use the actual name of the bucket.

If you check the syntax, bucket name should just be the name of the bucket and not the endpoint or URL of the bucket.

aws s3 cp --recursive ./file.txt s3://bucketname/

The above error is due to a policy issue; you do not have the correct permissions for that operation. Check this guide to add policy to the AWS S3 buckets:

http://blogs.aws.amazon.com/security/post/Tx3VRSWZ6B3SHAV/Writing-IAM-Policies-How-to-grant-access-to-an-Amazon-S3-bucket

Upvotes: 8

Ram K
Ram K

Reputation: 19

Please run aws configure command in your shell to set the default region.

You will be prompted for 4 key values. Two of them are default region and output format. The other two are keys related to access.

As user error2007s suggested use:

aws s3 cp file_path s3://bucket-name/path-of-object

Upvotes: 0

AYBABTU
AYBABTU

Reputation: 1026

Not sure why the form I was trying to use did no work - see my edit - I tried to follow the recommendation and it failed.

The way I solved it meanwhile is running, as advised

aws s3api get-bucket-location --bucket BUCKET

Then using the form of

s3://[bucket name] --region=[return_val_of_get_bucet_location]

If anyone can advise about running without a flag I'll appreciate it.

Upvotes: 0

Related Questions