DEV Community

KenjiGoh
KenjiGoh

Posted on • Updated on

Django-Amazon S3 RequestTimeTooSkewed Error on Linux

While working on an ecommerce marketplace project, one day all my product images that are stored on Amazon S3 ,via django-storages, are all down! Nightmare!

Upon researching, I realized the issue is that the time of my linux server is out of synced with Amazon's system clocks. Amazon S3 uses NTP (Network Time Protocol) to keep its system clocks accurate. NTP provides a standard way of synchronizing computer clocks on servers.

This is the error message I encountered:

Error executing "PutObject" on "https://s3.ap-southeast-1.amazonaws.com/s3.XXXX-YOUR-BUCKET-LINK-XXXX"; AWS HTTP error: Client error: `PUT https://s3.ap-south-1.amazonaws.com/s3.XXXX-YOUR-BUCKET-LINK-XXXX` resulted in a `403 Forbidden` response:
<?xml version="1.0" encoding="UTF-8"?>
<Error><Code>RequestTimeTooSkewed</Code><Message>The difference between the reque (truncated...)
RequestTimeTooSkewed (client): The difference between the request time and the current time is too large. - <?xml version="1.0" encoding="UTF-8"?>
<Error><Code>RequestTimeTooSkewed</Code><Message>The difference between the request time and the current time is too large.</Message><RequestTime>20180817T035220Z</RequestTime><ServerTime>2018-08-17T06:17:43Z</ServerTime><MaxAllowedSkewMilliseconds>900000</MaxAllowedSkewMilliseconds><RequestId>1BF4E523584F893B</RequestId></Error>
Enter fullscreen mode Exit fullscreen mode

Let's start by looking at Amazon S3 server time.

$ curl http://s3.amazonaws.com -v
Enter fullscreen mode Exit fullscreen mode

Then to check our own Linux server time, we can use

$ date
Enter fullscreen mode Exit fullscreen mode

Have a look at the time discrepancies, which is the source of the error.

Now let's install ntp

sudo apt-get install ntp
Enter fullscreen mode Exit fullscreen mode

Then open the ntp config file located in /etc/ntp.conf and replace the existing entries with the following:

Type this command to open the ntp config on your terminal:

vi /etc/ntp.conf
Enter fullscreen mode Exit fullscreen mode

Existing Entries in ntp config file:

server 0.ubuntu.pool.ntp.org
server 1.ubuntu.pool.ntp.org
server 2.ubuntu.pool.ntp.org
server 3.ubuntu.pool.ntp.org
Enter fullscreen mode Exit fullscreen mode

Replace with the following below:

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
Enter fullscreen mode Exit fullscreen mode

Now make sure you are in the root to run the final command.
If you have forgotten your root password, follow this:

$ sudo passwd root
Enter fullscreen mode Exit fullscreen mode

You will see the following prompt on your terminal to update the password.

[sudo] password for <user>: 
New password: 
Retype new password: 
passwd: password updated successfully
Enter fullscreen mode Exit fullscreen mode

Once you have updated your root password, type this:

$ su -
Enter fullscreen mode Exit fullscreen mode

Enter your new root password when prompt.
Then finally, in root, you can type in the final command to resolve the error.

root@DESKTOP-ABCDEF:~# service ntp restart
Enter fullscreen mode Exit fullscreen mode

You will see the NTP server restarting.

 * Stopping NTP server ntpd                    [ OK ] 
 * Starting NTP server ntpd                    [ OK ] 
Enter fullscreen mode Exit fullscreen mode

Go back to your project and magic has happened!
After encountering this error, i felt it is a good time to update myself on cloud computing knowledge! I found a decent online course on Coursera Shall start with this one day!

Thanks for reading!

Top comments (0)