解决因系统时间不对导致AWSAPI访问失败的问题

AWS二次开发时遇到的问题

问题:之前对AWS进行二次开发的时候,遇到了经典的”我本地是好的,怎么部署到服务器上之后报错了”这种问题,当时刚接触AWS不久,不禁怀疑是credentials的配置有问题,再三检查并与本机同步之后仍然存在该问题,翻阅StackOverflow之后找到了正确的解:

1
2
3
4
5
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

Amazon documents this behavior: “The EC2 CLI tools use your access keys as well as a time stamp to sign your requests. Ensure that your computer’s date and time are set correctly. If they are not, the date in the signature may not match the date of the request, and AWS rejects the request.”

也就是说AWS JavaSDK的 EndPoint除了校验你的秘钥以及region之外,还会校验系统的时钟设置是否正常,当时那台服务器的时间确实不对导致了访问失败。这个坑与代码无关,却是另一种时间的黑洞。

分享到:
0%