How to set --region with aws cli commands? - amazon-web-services

I am trying to run the following command:
aws s3 cp --region ap-south-1 --acl public-read my.exe s3://bucket/binaries/my.exe
upload failed: ./my.exe to s3://bucket/binaries/my.exe A client error
(InvalidRequest) occurred when calling the PutObject 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".
How do I fix this error? I also tried the
AWS_DEFAULT_REGION=ap-south-1 aws s3 cp --acl public-read my.exe s3://bucket/binaries/my.exe
but with no luck.
# aws --version
aws-cli/1.10.28 Python/2.7.9 Linux/3.16.0-4-amd64 botocore/1.4.19

It seems to be working after upgrading awscli.
pip install --upgrade awscli
aws --version
aws-cli/1.10.43 Python/2.7.9 Linux/3.16.0-4-amd64 botocore/1.4.33

Related

AWS S3 put-bucket-encryption operation failed with InvalidArgument error

I have been trying to enable default server-side encryption for s3 bucket. However, the command fails with the following error:
[root#dcm-development s3]# aws --profile S3-es-xx-xx-xx-test --endpoint-url https://es-xx-xx-z2.eecloud.xx.net s3api put-bucket-encryption --bucket bucketname --server-side-encryption-configuration '{"Rules": [{"ApplyServerSideEncryptionByDefault": {"SSEAlgorithm": "AES256"}}]}'
An error occurred (InvalidArgument) when calling the PutBucketEncryption operation: Unknown
awscli / Python version:
root#e3a8f6bbbdbc:/app# aws --version
aws-cli/1.18.117 Python/3.6.5 Linux/3.10.0-1062.9.1.el7.x86_64 botocore/1.17.40
I would really appreciate if someone can point out the mistake here. Other operations are working fine such as: put-bucket-policy, delete-bucket-policy, etc.

AWS QuickSight Embedding CLI error - aws: error: argument command: Invalid choice, valid choices are:

I am trying to embed a QuickSight Dashboard and am following the current steps.
https://aws.amazon.com/blogs/big-data/embed-interactive-dashboards-in-your-application-with-amazon-quicksight/
I'm at step 3 and able to assume the role and,
export AWS_ACCESS_KEY_ID="access_key_from_assume_role"
export AWS_SECRET_ACCESS_KEY="secret_key_from_assume_role "
export AWS_SESSION_TOKEN="session_token_from_assume_role"
However when I try and do the next step of calling "aws quicksight ..." from the next part I'm getting the following error,
aws: error: argument command: Invalid choice, valid choices are:
I've installed pip and made sure the command line text matches with correct details.
Has anyone experienced this or has any ideas why aws quicksight command wouldn't be working in the CLI?
Check AWS CLI version:
aws --version
It looks like the AWS CLI needs update.
To upgrade an existing AWS CLI installation, use the --upgrade option:
pip install --upgrade awscli
If you have pip3 then.
pip3 install --upgrade awscli
or
sudo pip3 install --upgrade awscli
Also remember that aws sts assume-role --role-arn has expiry token, to need to run this command again to get AWS_ACCESS_KEY_ID, AWS_SECRET_ACCESS_KEY and AWS_SESSION_TOKEN to continue.
What I did was I, I prepared a tempprofile for these credentials and used this profile in next aws quicksight commands.
e.g
aws configure set AWS_ACCESS_KEY_ID XXXXXXX --profile tempprofile
aws configure set AWS_SECRET_ACCESS_KEY XXXXXXXX--profile tempprofile
aws configure set AWS_SESSION_TOKEN XXXXXXX --profile tempprofile
In my case also I set
aws configure set REGION ap-southeast-2 --profile tempprofile
and then in next aws quicksight commands use --profile tempprofile

AWS s3 cp command returns: An error occurred (InvalidRequest) when calling the ListObjects operation

I've got a user with permission with the AmazonS3FullAccess policy, my bucketname is abcxyzchristest.
I've configured the AWS cli with the above user.
When running aws s3 cp --region eu s3://abcxyzchristest/ abcxyz I get:
fatal error: An error occurred (InvalidRequest) when calling the ListObjects operation: Missing required header for this request: x-amz-content-sha256
What is the cause of the error?
It was due the incorrect region specified.
I had to do:
aws s3 cp --region eu-central-1 s3://abcxyzchristest/ bobby
There are two steps to solve this problem:
1) Configure your command line aws
[root#ip-172-31-18-132 ec2-user]# aws configure
AWS Access Key ID [None]:
AWS Secret Access Key [None]:
Default region name [ap-south-1a]: ap-south-1 <-- give your region here
Default output format [None]:
2) Specify your region in the s3 cp command
aws s3 cp --recursive s3://buckername /home/ec2-user --region ap-south-1

aws cli signature version 4

I want to move all my data from Bucket1 of account A to Bucket2 of account B.
For this:
I downloaded AWS CLI for Windows.
Entered IAM credentials using command aws configure (these credentials are from account B)
Run command to sync buckets: aws s3 sync s3://Bucket1 s3://Bucket2
I received following error:
fatal error: An error occured (InvalidRequest) when calling the ListObject 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".
How to tackle this error?
aws --version
aws-cli/1.11.61 Python/2.7.9 windows/8 botocore/1.5.24
My S3 url was like :https://console.aws.amazon.com/s3/home?region=us-east-1
so I supposed that us-east-1 is my region but actually it was not!
I used AWS command to find Bucket2 region and it told me a different region.
Then I used this command aws s3 sync s3://Bucket1 s3://Bucket2 --region Asia Pacific (Mumbai) and everything worked fine!
Look for the correct region of the bucket (see attached image).
Try the command below by specifying the correct region:
aws s3 ls --region us-west-2
S3 is global - don't let that mislead you.

"aws s3 ls" command throwing "InvalidRequest" error message. How to solve it?

After I run aws s3 ls command I get below error message:-
A client error (InvalidRequest) occurred when calling the ListBuckets
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".
Below are more details and my findings that may help to answer the question:-
The command is being executed from an EC2 Instance running in ap-south-1 region.
This Amazon doc says that new region created after Jan 30 2014 only support Signature Version 4.
As suggested by error message I tried giving command aws --region ap-south-1 s3 ls but the this command also gives the same error message.
I have run yum update and the AWS CLI version is latest which is aws-cli/1.10.33 Python/2.7.10 Linux/4.4.11-23.53.amzn1.x86_64 botocore/1.4.23
The above aws s3 ls command works absolutely fine and lists the buckets if it is executed from an us-east-1 instance.
You need to update aws cli to latest version(v1.11.84 at the time of writing).
If yum update is not working then try following this Guide to install AWS CLI
The reason behind this error is, in newer regions AWS S3 doesn't support Lower Signature Version.
This worked for me:
sudo pip install --upgrade awscli
For Mac do sudo pip install awscli and that should fix the issue.