0
votes

I'm trying to remove the objects (empty bucket) and then copy new ones into an AWS S3 bucket:

aws s3 rm s3://BUCKET_NAME --region us-east-2 --recursive
aws s3 cp ./ s3://BUCKET_NAME/ --region us-east-2 --recursive

The first command fails with the following error:

An error occurred (InvalidRequest) when calling the ListObjects operation: You are attempting to operate on a bucket in a region that requires Signature Version 4. 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". Completed 1 part(s) with ... file(s) remaining

Well, the error prompt is self-explanatory but the problem is that I've already applied the solution (I've added the --region argument) and I'm completely sure that it is the correct region (I got the region the same way the error message is suggesting).

Now, to make things even more interesting, the error happens in a gitlab CI environment (let's just say some server). But just before this error occurs, there are other buckets which the exact same command can be executed against and they work. It's worth mentioning that those other buckets are in different regions.

Now, to top it all off, I can execute the command on my personal computer with the same credentials as in CI server!!! So to summarize:

server$ aws s3 rm s3://OTHER_BUCKET --region us-west-2 --recursive   <== works
server$ aws s3 rm s3://BUCKET_NAME --region us-east-2 --recursive  <== fails
my_pc$ aws s3 rm s3://BUCKET_NAME --region us-east-2 --recursive  <== works

Does anyone have any pointers what might the problem be?

1

1 Answers

1
votes

For anyone else that might be facing the same problem, make sure your aws is up-to-date!!!

server$ aws --version
aws-cli/1.10.52 Python/2.7.14 Linux/4.13.9-coreos botocore/1.4.42

my_pc$ aws --version
aws-cli/1.14.58 Python/3.6.5 Linux/4.13.0-38-generic botocore/1.9.11

Once I updated the server's aws cli tool, everything worked. Now my server is:

server$ aws --version
aws-cli/1.14.49 Python/2.7.14 Linux/4.13.5-coreos-r2 botocore/1.9.2