Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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] 
like image 652
Andrew Shore Avatar asked Aug 17 '15 19:08

Andrew Shore


People also ask

What is X AMZ date?

X-Amz-DateThe date that is used to create the signature. The format must be ISO 8601 basic format (YYYYMMDD'T'HHMMSS'Z'). For example, the following date time is a valid X-Amz-Date value: 20120325T120000Z .

What is AWS4 Hmac SHA256?

AWS4-HMAC-SHA256. The algorithm that was used to calculate the signature. You must provide this value when you use AWS Signature Version 4 for authentication.

How do I authenticate AWS S3?

For Amazon S3 request authentication, use your AWS secret access key ( YourSecretAccessKey ) as the key, and the UTF-8 encoding of the StringToSign as the message. The output of HMAC-SHA1 is also a byte string, called the digest. The Signature request parameter is constructed by Base64 encoding this digest.

What is the procedure to send a request to Amazon S3?

You can send requests to Amazon S3 using the REST API or the AWS SDK (see Sample Code and Libraries ) wrapper libraries that wrap the underlying Amazon S3 REST API, simplifying your programming tasks. Every interaction with Amazon S3 is either authenticated or anonymous.


1 Answers

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

like image 140
Andrew Shore Avatar answered Sep 26 '22 02:09

Andrew Shore