AWS Java 开发工具包 - AWS 身份验证需要有效的日期或 x-amz-date 标头

在使用适用于 Java 和 Java 的 AWS 开发工具包 1.8u60+ 时出现以下异常。

com.amazonaws.services.s3.model.AmazonS3Exception: AWS authentication requires a valid Date or x-amz-date header (Service: Amazon S3; Status Code: 403; Error Code: AccessDenied; Request ID: 41C359C079CBAFCF)
    at com.amazonaws.http.AmazonHttpClient.handleErrorResponse(AmazonHttpClient.java:1182) ~[aws-java-sdk-core-1.10.10.jar:na]
    at com.amazonaws.http.AmazonHttpClient.executeOneRequest(AmazonHttpClient.java:770) ~[aws-java-sdk-core-1.10.10.jar:na]
    at com.amazonaws.http.AmazonHttpClient.executeHelper(AmazonHttpClient.java:489) ~[aws-java-sdk-core-1.10.10.jar:na]
    at com.amazonaws.http.AmazonHttpClient.execute(AmazonHttpClient.java:310) ~[aws-java-sdk-core-1.10.10.jar:na]
    at com.amazonaws.services.s3.AmazonS3Client.invoke(AmazonS3Client.java:3608) ~[aws-java-sdk-s3-1.10.10.jar:na]
    at com.amazonaws.services.s3.AmazonS3Client.invoke(AmazonS3Client.java:3561) ~[aws-java-sdk-s3-1.10.10.jar:na]
    at com.amazonaws.services.s3.AmazonS3Client.listObjects(AmazonS3Client.java:647) ~[aws-java-sdk-s3-1.10.10.jar:na]
    at com.amazonaws.services.s3.AmazonS3Client.listObjects(AmazonS3Client.java:632) ~[aws-java-sdk-s3-1.10.10.jar:na]

答案 1

这是由JodaTime和大于1.8u60的Java版本之间的错误引起的。升级到JodaTime版本2.8.1或更高版本可以解决此问题。请参阅以下 Github 问题以供参考。

https://github.com/aws/aws-sdk-java/issues/484 https://github.com/aws/aws-sdk-java/issues/444


答案 2

据我所知,这个问题有三种解决方案:

  • 升级乔达时间
  • 升级 AWS Java 开发工具包
  • 将java降级到低于1.8u60的版本(java7似乎工作正常)

推荐