43

我按照亚马逊指南安装了 ec2 api。我将访问 ID 和密码设置为环境变量。

这是我的个人资料:

导出 AWS_ACCESS_KEY=XXXXX

导出 AWS_SECRET_KEY=XXXXXX

导出 JAVA_HOME=/usr/lib/jvm/java-7-openjdk-amd64/jre

导出 EC2_HOME=/usr/local/ec2/ec2-api-tools-1.7.1.0

导出 PATH=$PATH:$EC2_HOME/bin

一切看起来都按照要求进行了配置,但我无法连接到 aws。

这里是详细模式下命令 ec2-describe-regions 的输出:

Client.AuthFailure: AWS was not able to validate the provided access credentials
ubuntu@ip:~$ ec2dre -v
Setting User-Agent to [ec2-api-tools 1.7.1.0]
2014-07-14 19:10:34,898 [main] DEBUG org.apache.http.wire  - >> "POST / HTTP/1.1[\r][\n]"
2014-07-14 19:10:34,912 [main] DEBUG org.apache.http.wire  - >> "Host: ec2.amazonaws.com[\r][\n]"
2014-07-14 19:10:34,912 [main] DEBUG org.apache.http.wire  - >> "X-Amz-Date: 20140714T191033Z[\r][\n]"
2014-07-14 19:10:34,913 [main] DEBUG org.apache.http.wire  - >> "Authorization: AWS4-HMAC-SHA256 Credential=AKIAIT64V5MH2HHF5QZQ/20140714/us-east-1/ec2/aws4_request, SignedHeaders=host;user-agent;x-amz-date, Signature=06920c7d37a24d8244feb630d87310238886294d3ae2ab40f68a362a799d9a62[\r][\n]"
2014-07-14 19:10:34,913 [main] DEBUG org.apache.http.wire  - >> "User-Agent: ec2-api-tools 1.7.1.0, aws-sdk-java/unknown-version Linux/3.2.0-36-virtual OpenJDK_64-Bit_Server_VM/24.51-b03[\r][\n]"
2014-07-14 19:10:34,913 [main] DEBUG org.apache.http.wire  - >> "Content-Type: application/x-www-form-urlencoded; charset=utf-8[\r][\n]"
2014-07-14 19:10:34,913 [main] DEBUG org.apache.http.wire  - >> "Content-Length: 41[\r][\n]"
2014-07-14 19:10:34,913 [main] DEBUG org.apache.http.wire  - >> "Connection: Keep-Alive[\r][\n]"
2014-07-14 19:10:34,913 [main] DEBUG org.apache.http.wire  - >> "[\r][\n]"
2014-07-14 19:10:34,914 [main] DEBUG org.apache.http.wire  - >> "Action=DescribeRegions&Version=2014-06-15"
2014-07-14 19:10:34,984 [main] DEBUG org.apache.http.wire  - << "HTTP/1.1 401 Unauthorized[\r][\n]"
2014-07-14 19:10:35,002 [main] DEBUG org.apache.http.wire  - << "Transfer-Encoding: chunked[\r][\n]"
2014-07-14 19:10:35,003 [main] DEBUG org.apache.http.wire  - << "Date: Mon, 14 Jul 2014 19:18:34 GMT[\r][\n]"
2014-07-14 19:10:35,003 [main] DEBUG org.apache.http.wire  - << "Server: AmazonEC2[\r][\n]"
2014-07-14 19:10:35,010 [main] DEBUG org.apache.http.wire  - << "[\r][\n]"
2014-07-14 19:10:35,225 [main] DEBUG org.apache.http.wire  - << "fe[\r][\n]"
2014-07-14 19:10:35,225 [main] DEBUG org.apache.http.wire  - << "<?xml version="1.0" encoding="UTF-8"?>[\n]"
2014-07-14 19:10:35,225 [main] DEBUG org.apache.http.wire  - << "<Response><Errors><Error><Code>AuthFailure</Code><Message>AWS was not able to validate the provided access credentials</Message></Error></Errors><RequestID>cd2b128b-3d70-425b-a8a7-4856fd9a6b99</RequestID></Response>"
2014-07-14 19:10:35,278 [main] DEBUG org.apache.http.wire  - << "[\r][\n]"
2014-07-14 19:10:35,279 [main] DEBUG org.apache.http.wire  - << "0[\r][\n]"
2014-07-14 19:10:35,279 [main] DEBUG org.apache.http.wire  - << "[\r][\n]"
Client.AuthFailure: AWS was not able to validate the provided access credentials
Request ID: cd2b128b-3d70-425b-a8a7-4856fd9a6b99
4

7 回答 7

100

检查服务器时钟是否同步

如果时钟延迟,可能会导致此错误:

AWS was not able to validate the provided access credentials
于 2015-03-12T16:30:15.033 回答
19

当我的系统时钟设置错误时,我遇到了这个问题。

就我而言,时钟提前了两个小时。

同样重要的是将命令放在您的 .bashrc 或类似文件 (.bash_aliases) 中:

export AWS_ACCESS_KEY="XXXXXXXXXXXXXXXXX"
export AWS_SECRET_KEY="XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX"

跑的时候source ~/.bashrc

之所以如此重要,是因为在运行 ec2 命令时会创建新的 shell 实例,否则不会获取环境变量。

于 2014-08-21T12:52:49.943 回答
9

运行aws s3 ls确认错误是否与时间同步有关。你应该得到如下错误:

调用ListBuckets操作时出错(RequestTimeTooSkewed):请求时间与当前时间相差过大。

如果是这样,请尝试按照建议同步您的日期时间。

Linux 上执行此操作的示例 shell 命令:

# Install the ntpdate client for setting system time from NTP servers.
sudo apt-get --yes install ntpdate
sudo ntpdate 0.amazon.pool.ntp.org

然后再次重试您的aws命令。


如果时区仍然不正确,sudo dpkg-reconfigure tzdata请运行:配置它,或者通过:

timedatectl list-timezones
timedatectl set-timezone 'Europe/London'

另请参阅:配置本地时间。dpkg-重新配置 tzdata

于 2018-02-05T14:53:01.773 回答
5

AWS CLI 对我来说工作正常,但突然之间它开始失败并出现以下错误

A client error (AuthFailure) occurred when calling the DescribeTags operation: AWS was not able to validate the provided access credentials

尝试使用一组新凭据,但这没有帮助。

它仅在 EC2 实例上执行停止启动后才起作用(重新启动也可能起作用)。因此,执行 aws cli 的特定 EC2 实例似乎存在问题。

于 2016-01-12T13:47:44.537 回答
3

我有一个类似的问题。我本地服务器上的时钟已关闭。我用以下命令纠正了它。

sudo date -s "$(wget -qSO- --max-redirect=0 google.com 2>&1 | grep 日期:| cut -d' ' -f5-8)Z"

然后,aws 工作。

于 2018-12-20T22:18:11.203 回答
3

这也可能是由于一个问题,具体取决于您要到达的区域。我有一个脚本试图在所有地区担任角色,并在香港(ap-east-1)不断得到这个。您必须首先启用此区域才能访问它。如果您未启用以下区域,您将收到此错误:

ap-east-1
cn-north-1
cn-northwest-1
us-gov-east-1
us-gov-west-1

奇怪的是,ap-northeast-3也给出了一个错误,但它的错误是OptInRequired.

于 2019-06-18T07:38:29.467 回答
0

对于 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

您还可以再次重新配置 aws 凭证

aws configure
于 2020-05-31T04:05:42.977 回答