I installed the ec2 api following the amazon guide. I setted up the access id and secret as environment variable.
Here it is my profile:
expor
I ran into this issue when my system clock was set falsely.
In my case the clock was running ahead by two hours.
Equally important is to put the commands in your .bashrc or similar file (.bash_aliases):
export AWS_ACCESS_KEY="XXXXXXXXXXXXXXXXX"
export AWS_SECRET_KEY="XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX"
When there run source ~/.bashrc
The reason for the importance of this is that when running an ec2 command new shell instances are created that doesn't get the environment variables otherwise.
This can also be due to an issue depending on which region you're trying to reach. I have a script trying to assume roles in all regions and kept getting this in Hong Kong (ap-east-1). You have to first enable this region in order to access it. You'll get this error for the following regions if you don't have them enabled:
ap-east-1
cn-north-1
cn-northwest-1
us-gov-east-1
us-gov-west-1
Strangely, ap-northeast-3
also gives an error but it's error is OptInRequired
.
Check that the server clock is synchronized.
If the clock is delayed, can cause this error:
AWS was not able to validate the provided access credentials
I had a similar issue. The clock on my local server was off. I corrected it with the following command.
sudo date -s "$(wget -qSO- --max-redirect=0 google.com 2>&1 | grep Date: | cut -d' ' -f5-8)Z"
Then, aws worked.
For CentOS
# install ntpdate
sudo yum install ntpdate
# install policy kit
sudo yum install polkit
# start ntpd service
sudo systemctl start ntpd.service
sudo ntpdate 0.amazon.pool.ntp.org
You can also reconfigure aws credential again
aws configure
Run aws s3 ls
to confirm whether the error is related to time sync. You should get the error like:
An error occurred (RequestTimeTooSkewed) when calling the ListBuckets operation: The difference between the request time and the current time is too large.
If so, try to sync your datetime as suggested.
Example shell commands on Linux to do that:
# Install the ntpdate client for setting system time from NTP servers.
sudo apt-get --yes install ntpdate
sudo ntpdate 0.amazon.pool.ntp.org
Then re-try your aws
command again.
If the timezone is still not correct, run: sudo dpkg-reconfigure tzdata
to configure it, or by:
timedatectl list-timezones
timedatectl set-timezone 'Europe/London'
See also: Configure localtime. dpkg-reconfigure tzdata.