S3 Error: The difference between the request time and the current time is too large

Amazon S3

Amazon S3 Problem Overview


I have error The difference between the request time and the current time is too large when call method amazons3.ListObjects

ListObjectsRequest request = new ListObjectsRequest() {
    BucketName = BucketName, Prefix = fullKey 
}; 
using (ListObjectsResponse response = s3Client.ListObjects(request))
{
    bool result = response.S3Objects.Count > 0;
                    
    return result;
}

What it could be?

Amazon S3 Solutions


Solution 1 - Amazon S3

The time on your local box is out of sync with the current time. Sync up your system clock and the problem will go away.

Solution 2 - Amazon S3

For those using Vagrant, a vagrant halt followed by vagrant up worked for me.

Solution 3 - Amazon S3

The clock is out of sync.

I followed the steps in this post to get it working again, but also had to run the following command.

sudo ntpdate ntp.ubuntu.com
sudo apt-get install ntp

If at any time you get a message saying the NTP socket is still in use, stop it with sudo /etc/init.d/ntp stop and re-run your command.

Solution 4 - Amazon S3

I had the same error and I'm using Docker for Mac. Simply restarting Docker worked for me.

Solution 5 - Amazon S3

For those using Docker in Windows try restarting the Docker Engine in Setting->Reset->Restart Docker.

Solution 6 - Amazon S3

In case anyone finds this using Laravel and Homestead, simply running

homestead halt

followed by

homestead up

And you're good to go again.

Solution 7 - Amazon S3

As other's have said, your local clock is out of sync with AWS. You can keep it sync'd to Amazon's servers directly using NTP so you won't have to worry about clock drift now or in the future.

Note: The below instructions are for *nix users. I've added a comment with how you might do it in Windows, but as a non-Windows user I can't verify their accuracy.

> 1. To install NTP, simply choose one of the following, depending on your distribution: > > apt-get install ntp > or > > yum install ntp > etc. > > 2. Configure NTP to use amazon servers, like so: > > vim /etc/ntp.conf > > And in it, comment out the default servers and add these: > > server 0.amazon.pool.ntp.org iburst > server 1.amazon.pool.ntp.org iburst > server 2.amazon.pool.ntp.org iburst > server 3.amazon.pool.ntp.org iburst > > 3. And then restart ntp service: > > sudo service ntp restart

Source: https://www.allcloud.io/how-to/how-to-fix-amazon-s3-requesttimetooskewed/

And a more general article on keeping your time synchronized with NTP: https://www.digitalocean.com/community/tutorials/how-to-set-up-time-synchronization-on-ubuntu-12-04

Solution 8 - Amazon S3

On WSL 2 or any Deb-based Linux (Ubuntu, Mint ...):

Check date:

date

Now run:

sudo apt install ntpdate 
sudo ntpdate  time.nist.gov

Output example:

18 Feb 14:27:36 ntpdate[24008]: step time server 132.163.97.4 offset 1009.140848 sec

Check date again:

date

Solution 9 - Amazon S3

2021 answer:

AWS.config.update({
    accessKeyId: 'xxx',
    secretAccessKey: 'xxxx',
    correctClockSkew: true
});

Solution 10 - Amazon S3

This can also be caused by using async/await with the construction of the request object outside the task and the actual call to AWS inside the task. If there are lots of tasks running and the task isn't scheduled in time, or there is some other operation delaying the actual call to AWS, this exception may be thrown.

Solution 11 - Amazon S3

This reset my system clock correctly on OSX. S3 uploads using the JS SDK works for me now in local dev

ntpdate us.pool.ntp.org

Read more about this here

Solution 12 - Amazon S3

if this problem in you localhost for windows 10

set time automatically ON and set time zone automatically ON this solve my problem.

enter image description here

Solution 13 - Amazon S3

If you get this error in windows follow these steps to solve your problem.. Change your local time setting:
step 1: click on change date and time settings
step 2: from the popup Date and Time window click on Internet Time Tab
step 3: next Click on Change Settings
step 4: from the Server drop down select time.nist.gov or check this website
step 5: click on OK

Restart your console and check. It works...

Solution 14 - Amazon S3

For those facing same problem on Microsoft WLS2 Ubuntu, the only workarounds right now are:

sudo hwclock -s

Or

wsl --shutdown 

Clock offset is occurring after waking up Windows from sleep. Keep an eye on https://github.com/microsoft/WSL/issues/5324 for fix from microsoft.

Solution 15 - Amazon S3

If you're working with a VM, restarting the VM just works on mine

Solution 16 - Amazon S3

To get rid of this problem, you have to adjust the client's timing so that there is a maximum time stamp difference of up to 15 minutes. Also set the standard time and zone for your system.

Check the full Detail here.

Solution 17 - Amazon S3

If you are using a virtualbox, the time into virtual machine is sync with the time of the real machine. Just fix the time into the virtual machine will not fix the problem.

Solution 18 - Amazon S3

I had this error because my local machine's time and timezone were set incorrectly. Changing them to the correct time and timezone worked for me.

Solution 19 - Amazon S3

I had same problem in Windows 10 with Docker. You should run this commands step for step

docker run --rm --privileged alpine hwclock -s

again

docker run --rm --privileged alpine hwclock -s

and last command , don't forget to set your username and password and your timezone, to run minIO while Docker is

docker run -p 9000:9000 -e "MINIO_ACCESS_KEY=yourUserName" -e "MINIO_SECRET_KEY=YourPassword" -e "TZ=Europe/Berlin" -v /etc/localtime:/etc/localtime:ro  minio/minio server /data

Solution 20 - Amazon S3

Using ntp may not work on all version of your Linux based server (e.g. an out of date Ubuntu server version that is no longer supported which will block you from downloading ntp if it is not already installed).

If this is your situation, you can set independent time zones for your Linux VM: https://community.rackspace.com/products/f/25/t/650

After you do this you may need to reset the time/date. Instructions for doing this are in this article: http://codeghar.wordpress.com/2007/12/06/manage-time-in-ubuntu-through-command-line

Solution 21 - Amazon S3

If u are in 2016 and in Istanbul here is a weird situation that Turkey decided not to switch to winter time standards anyway set your local timezone to Moscow then restart your machine.

Solution 22 - Amazon S3

I ran into this issue running Jet (Codeship) and Terraform on MacOS using Docker for Mac Beta channel 1.13.1-beta42.

Failed to read state: Error reloading remote state: RequestTimeTooSkewed: The difference between the request time and the current time is too large.
status code: 403, request id: 9D32BA2A5360FC18

This was resolved by restarting Docker.

Solution 23 - Amazon S3

I've just started getting this error, and syncing my clock doesn't help. (I've spent 2 hours syncing it to every timeserver I can find, including the AWS servers, but nothing makes a difference.)

Exactly the same thing started happening a year ago on Dec 31 2017. In that case, rebooting my system, and rebuilding my server (that uses the aws java sdk) fixed it. I don't know why. I assumed that AWS had some end-of-year timezone peculiarity. It's also possible that while I was doing these things, AWS timeservers fixed themselves. I have no way to test that hypothesis.

Now, the same thing has suddenly started to happen on Dec 30, 2018. It's not right at year-end, but close enough to seem suspicious. (Never got this error except on these dates.) Rebooting and rebuilding isn't helping this time.

My dev environment on this box is Windows 10 under Parallels. Nothing else on my system has changed - as I've double-checked by rolling back to prior Parallels snapshots. The clocks on both my host MacOS and the virtual Windows 10 are correct.

I'm suspecting an AWS bug.

Solution 24 - Amazon S3

Rebooting my windows server fixed it for me

The time was identical to ~1 second to the site time.in, so it wasn't off.

Solution 25 - Amazon S3

+1 @sompnd - I was able to execute CLI commands in a container after running wsl --shutdown

Solution 26 - Amazon S3

I was running into the same issue on my Mac. When I moved to a different timezone(PST to IST), somehow OSX was not picking timezone and time change automatically. So I had to set the two manually and that caused a lag of some 15-20 seconds on my laptop. After setting the automatic sync, the time got synched and the S3 copy command started working: For reference

Solution 27 - Amazon S3

It is a little crude but this worked for me

  1. Did a curl to s3 server

    curl s3.amazonaws.com -v

Then got this

* Trying 52.216.141.158...
* TCP_NODELAY set
* Connected to s3.amazonaws.com (52.216.141.158) port 80 (#0)
> GET / HTTP/1.1
> Host: s3.amazonaws.com
> User-Agent: curl/7.64.1
> Accept: */*
>
< HTTP/1.1 307 Temporary Redirect
< x-amz-id-2: q2wUOf5ZC7iu2ymbRWUpZaM6GpPLLf/irrntuw/JNB7QYxDzQvcLHQbsbF2dp5zT8rBrGwqnOz0=
< x-amz-request-id: T4H1W4WKBE3F39RM
< Date: Sat, 09 Oct 2021 19:21:24 GMT
< Location: https://aws.amazon.com/s3/
< Server: AmazonS3
< Content-Length: 0
<
* Connection #0 to host s3.amazonaws.com left intact
* Closing connection 0
  1. Got this date Sat, 09 Oct 2021 19:21:24 GMT

  2. Set the date in ubuntu sudo date --set "Sat, 09 Oct 2021 19:21:24 GMT"

My code stopped throwing exceptions Now I have a script that does this periodically every month

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
Questionst78View Question on Stackoverflow
Solution 1 - Amazon S3Mark At Ramp51View Answer on Stackoverflow
Solution 2 - Amazon S3Czar PinoView Answer on Stackoverflow
Solution 3 - Amazon S3manafireView Answer on Stackoverflow
Solution 4 - Amazon S3Dylan O'CarrollView Answer on Stackoverflow
Solution 5 - Amazon S3Julio ColonView Answer on Stackoverflow
Solution 6 - Amazon S3CitizenView Answer on Stackoverflow
Solution 7 - Amazon S3Kyle ChadhaView Answer on Stackoverflow
Solution 8 - Amazon S3Ivan BorshchovView Answer on Stackoverflow
Solution 9 - Amazon S3lucaswxpView Answer on Stackoverflow
Solution 10 - Amazon S3JamesView Answer on Stackoverflow
Solution 11 - Amazon S3phoenixboxView Answer on Stackoverflow
Solution 12 - Amazon S3Atul BaldaniyaView Answer on Stackoverflow
Solution 13 - Amazon S3LaxminarayanaView Answer on Stackoverflow
Solution 14 - Amazon S3sompndView Answer on Stackoverflow
Solution 15 - Amazon S3Denimar FernandezView Answer on Stackoverflow
Solution 16 - Amazon S3Nikunj DhimarView Answer on Stackoverflow
Solution 17 - Amazon S3Thiago MataView Answer on Stackoverflow
Solution 18 - Amazon S3Adim VictorView Answer on Stackoverflow
Solution 19 - Amazon S3SaeedView Answer on Stackoverflow
Solution 20 - Amazon S3socialmatchboxView Answer on Stackoverflow
Solution 21 - Amazon S3Ömer Faruk AlmalıView Answer on Stackoverflow
Solution 22 - Amazon S3EvilPlanktonView Answer on Stackoverflow
Solution 23 - Amazon S3thundView Answer on Stackoverflow
Solution 24 - Amazon S3user2728841View Answer on Stackoverflow
Solution 25 - Amazon S3Kevin GrimmView Answer on Stackoverflow
Solution 26 - Amazon S3pythonLover8433View Answer on Stackoverflow
Solution 27 - Amazon S3Sidharth SahuView Answer on Stackoverflow