Amazon ec2 验证访问凭据时发生EC2 API错误

Amazon ec2 验证访问凭据时发生EC2 API错误,amazon-ec2,ec2-api-tools,Amazon Ec2,Ec2 Api Tools,我按照amazon指南安装了EC2API。我将访问id和secret设置为环境变量 这是我的个人资料: 导出AWS\u访问\u密钥=XXXXX 导出AWS\u密钥\u密钥=XXXXXX 导出JAVA_HOME=/usr/lib/jvm/JAVA-7-openjdk-amd64/jre 导出EC2_HOME=/usr/local/EC2/EC2-api-tools-1.7.1.0 导出路径=$PATH:$EC2_HOME/bin 一切看起来都按要求配置,但我无法连接到aws 此处,命令ec2的输出

我按照amazon指南安装了EC2API。我将访问id和secret设置为环境变量

这是我的个人资料:

导出AWS\u访问\u密钥=XXXXX

导出AWS\u密钥\u密钥=XXXXXX

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

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

导出路径=$PATH:$EC2_HOME/bin

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

此处,命令ec2的输出以详细模式描述区域:

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

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

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

同样重要的是将命令放在.bashrc或类似文件(.bash\u别名)中:

当运行
source~/.bashrc


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

检查服务器时钟是否同步

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

AWS was not able to validate the provided access credentials

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实例似乎存在问题。

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

调用ListBucket操作时发生错误(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'

另请参见:。

我也有类似的问题。我本地服务器上的时钟关闭了。我用下面的命令更正了它

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


然后,aws成功了。

这也可能是由于问题,具体取决于您试图到达的地区。我有一个脚本试图承担所有区域中的角色,并在香港(AP-EAST-1)保持这个角色。您必须首先启用此区域才能访问它。如果未启用以下区域,则会出现此错误:

ap-east-1
cn-north-1
cn-northwest-1
us-gov-east-1
us-gov-west-1
奇怪的是,
ap-northeast-3
也给出了一个错误,但它的错误是
OptInRequired

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

对于>500 rep,您应该更清楚:向我们展示您的代码,以及运行代码的用户的环境(不带值)@alfasin如果没有涉及代码,我只执行ec2dre来检查环境。我在消息中更新了我的配置文件环境变量。你所说的“大于500”纳米是什么意思?500纳米是什么环境<代码>根目录?哪个用户连接到AWS?我正在连接一个id和gid为1000的普通用户。我也试过使用root,但我得到了同样的错误。我使用了mac上的相同凭证,它们也可以工作,但ubuntu上的时间对我来说不是10分钟,安装了NTP来解决这个问题,同时通过Boot2Docker在Docker容器中运行Fog。帮助我重置Boot2Docker VM上的时间。在.zshrc或.bashrc中的export命令非常重要。除非您进行更新,否则会导出旧密钥。您是如何获得此解决方案的?无论如何!它起作用了:)ThxAmazon记录了这种行为:“EC2 CLI工具使用您的访问密钥和时间戳对您的请求进行签名。确保计算机的日期和时间设置正确。如果设置不正确,签名中的日期可能与请求的日期不匹配,AWS将拒绝请求。”
aws s3 ls
:调用ListBucket操作时发生错误(RequestTimeTooSkewed):请求时间与当前时间之间的差异太大。执行开始-停止操作对我也有效。谢谢
aws configure