2
votes

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

  • Then executed

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".

3
what is the name of the bucket?error2007s
Lets call it bucket_name - it is all lower case if that is what you are asking, in a form of x.comAYBABTU
watch out for trailing slashesgrepe

3 Answers

8
votes

You are using the endpoint of the bucket do not use that. Use the actual name of the bucket. Check this syntax bucket name should be just 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 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

0
votes

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.

0
votes

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