164

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?

30 Answers 30

221

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.

17
  • 3
    I've faced the same error. Please tell me how to perform synchronization
    – Stas
    May 22, 2012 at 9:35
  • 71
    I dream of the day that error messages are more direct, "Your server time is set incorrectly" would be just fine with me.
    – adamdport
    Sep 2, 2014 at 13:35
  • 1
    Any way to avoid this? I don't wanna change my computer's timezone because I'm in a different country.
    – casraf
    Dec 8, 2014 at 15:06
  • 2
    The time zone setting shouldn't matter. It's the accuracy of the currently set time that's important. Dec 9, 2014 at 16:24
  • 3
    In Australia we just went into daylight savings (1 hour ahead) and now this error is being thrown. My clock is correct. Seems to be a bug in AWS.
    – Luke
    Oct 2, 2016 at 0:21
84

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

0
78

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.

3
  • Yay, this fixed my problem. If you don't have apt-get, use yum instead: sudo yum install ntp -y Jan 31, 2016 at 13:14
  • 1
    Worked. I only had to run sudo ntpdate ntp.ubuntu.com on my server, though.
    – spnkr
    May 17, 2018 at 0:56
  • Just the sudo ntpdate ntp.ubuntu.com worked for me on WSL2 + Ubuntu, as well, when all other solutions didn't.
    – kevlarr
    Mar 15, 2021 at 19:06
39

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

Alternatively look for correctClockSkew option in AWS CLI/SDK config, and set it to true

AWS.config.update({
   correctClockSkew: true
});
1
  • 1
    This worked for me on Ubuntu on WSL 2. When I first tried to fix this a few days ago, I tried another command that appeared to be a generic fix. It was something like sudo systemctl <reset_time> and I got an error saying "systemd not loaded" or something like that, since it's WSL. This command worked though. I ran it, it said there was some sort of offset that it corrected, and then when I ran aws s3 ls I didn't get the error anymore.
    – Matt Welke
    May 6, 2021 at 1:54
29

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

16

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

0
15

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

homestead halt

followed by

homestead up

And you're good to go again.

0
13

2021 answer:

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

As other's have said, your local clock is out of sync with AWS. You can keep it synced 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. Restart ntp service:

    sudo service ntp restart
    

Source: https://allcloud.io/blog/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

2
  • C:\Users\User>apt-get install ntp 'apt-get' is not recognized as an internal or external command, operable program or batch file.
    – st78
    May 4, 2017 at 5:57
  • 1
    apt-get is a package installer for certain linux distributions. For windows, you can do a search online for the best way to sync to NTP. Here's a reference I found for win10: tenforums.com/tutorials/… , and here's one for Windows Server: support.microsoft.com/en-us/help/816042/… May 5, 2017 at 15:16
9

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. This is more common than you might guess because the default task scheduler does not process tasks in FIFO order, resulting in starvation for some tasks, especially under heavy load.

6

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

5

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

1
  • 1
    Also worked (for me) on Ubuntu 23.04.
    – dvlper
    Jun 5, 2023 at 18:48
5

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.

1
  • running sudo ntpdate time.nist.gov will bandaid fix it though
    – Kent Wong
    Jul 30, 2021 at 14:20
3

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...

0
2

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

1

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.

1

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.

1

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
1

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

1
  • 1
    why you don't use NTP in your server? Nov 18, 2021 at 18:39
1

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 details here.

1
  • @BhanuTez : ya article might be removed. It's been 7 years :) Aug 23, 2021 at 17:05
1

I have the exact same error message but it's not the same cause as any of the others above.

In my case I have a React browser app doing something like this:

import { Storage } from '@aws-amplify/storage'
...
await Promise.all(files.map(file => Storage.put(...)))

I am uploading a lot of files over a slow network connection.

With this code, the promises are all started at once, so the request time for all the requests is the same, but because the browser (or amplify?) is throttling the number of concurrent connections, the later requests don't actually hit the server until more than 15 minutes after they were created.

The solution is to limit the concurrency of the promise creation - e.g. use something like bluebird Promise.map with the concurrency option

0

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

0

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.

0
0

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.

0

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.

1
  • I had the same issue... zipping the file worked for me as was an 1.3GB csv file I was attempting to upload.. once below 500MB the issue went away. I was not using AWS CLI but a connector from SSIS on a hosted EC2 instance on another AWS account
    – Chris Wood
    Feb 2, 2022 at 16:42
0

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.

0

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

0

You can use this tool for organizing your time with AWS and local system.

To synchronize time:

sudo yum -y install chrony
sudo systemctl enable chronyd
sudo systemctl start chronyd
0

This issue generally occurs when s3cmd client machine time is not synced with server.

Check time of both machine.

either sync time between them using date command

Client# sudo date --set="string"
Client# sudo date --set="15 MAY 2011 1:40 PM"

or

install chrony and restart its service on both machine

Client# sudo apt-get install chrony
Client# vi /etc/chrony/chrony.conf

pool ntp-server iburst

Client# sudo systemctl restart chronyd
0

I had this problem in windows with wsl. Not shure if is your situation. But in my case, the problem was that WSL was running in a diferent timezone.

You can ajust that using the follow code in your wls terminal:

sudo ntpdate pool.ntp.org

ntpdate is not a default packages, you may need to install it with apt-get in yout wsl distribution

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.