AWS Java SDK - AWS authentication requires a valid Date or x-amz-date header
Asked Answered
C

7

53

Getting the following exception when using the AWS SDK for Java and Java 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]
Chaste answered 17/8, 2015 at 19:43 Comment(1)
please specify what is the questione.Thinking
C
87

This is caused by a bug between JodaTime and versions of Java greater then 1.8u60. Upgrading to JodaTime version 2.8.1 or later solves the issue. See the following Github issues for reference.

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

Chaste answered 17/8, 2015 at 19:45 Comment(1)
Why is this not an accepted answer? Anyway, thanks man, saved me a lot of time!Fondea
H
5

As far as I can see, there are three solutions to this issue:

  • upgrade joda time
  • upgrade the AWS java SDK
  • downgrade java to a version less than 1.8u60 (java7 seems to work fine)
Huggermugger answered 25/1, 2016 at 16:43 Comment(1)
is there a newer java update that fixes the issue? is this a bug with java or is this always going to break with future java releases?Drongo
B
4

Update your AWS Java SDK to 1.10.1 or later

Battue answered 5/1, 2016 at 17:28 Comment(1)
I updated AWS Java SDK to 1.10.10 but still got this error.Devisable
I
2

I faced while using presto. The problem is with java version jdk1.8.0_60 greater downgrade it to jdk1.8.0_45 will solve the problem

Invalidism answered 8/6, 2016 at 5:58 Comment(1)
downgrading JDK is not the answer. better update Joda as suggested above - via updating AWS SDK or explicitlyInattention
R
1

i have faced same problem.i have solved now.only thing is that java 1.8u60+ does not support aws sdk 1.10.10 so you can just update aws sdk version 1.11.52 ..i mean latest version and it resolved it.

Also please look out for the conflicts in the dependency tree, when you upgrade the versions. In my case there was a conflict with the httpclient after upgrading aws sdk version.

Retene answered 20/6, 2017 at 14:30 Comment(0)
A
0

All the answers above drove me nuts because they recommend changing libraries, clients or some other major change. I have to use client 1.9.31 and I don't have control over which joda or JVM. So here is the java fix without having to do everything above!

Before you send your request, like PutObjectRequest, do this:

putObjectRequest.putCustomRequestHeader("x-amz-date", getServerTime());

public static String getServerTime() {
    SimpleDateFormat dateFormat = new SimpleDateFormat(
        "EEE, dd MMM yyyy HH:mm:ss Z", Locale.US);
    return dateFormat.format(Calendar.getInstance().getTime());
}
Augur answered 9/2, 2021 at 0:12 Comment(0)
P
0

To solve this problem you must add the joda-time-2.10.13.jar library to the project.

Paraesthesia answered 1/10, 2023 at 1:19 Comment(2)
Welcome to Stack Overflow! Thank you for your answer. Please provide more details about your solution. Code snippets, high quality descriptions, or any relevant information would be great. Clear and concise answers are more helpful and easier to understand for everyone. Edit your answer with specifics to raise the quality of your answer. For more information: How To: Write good answers. Happy coding!Salangi
Your answer could be improved with additional supporting information. Please edit to add further details, such as citations or documentation, so that others can confirm that your answer is correct. You can find more information on how to write good answers in the help center.Sentimentalism

© 2022 - 2024 — McMap. All rights reserved.