DEV Community

KenjiGoh
KenjiGoh

Posted on • Edited on

3

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!

Image of Timescale

Timescale – the developer's data platform for modern apps, built on PostgreSQL

Timescale Cloud is PostgreSQL optimized for speed, scale, and performance. Over 3 million IoT, AI, crypto, and dev tool apps are powered by Timescale. Try it free today! No credit card required.

Try free

Top comments (1)

Collapse
 
s_group profile image
s group

hi,i had the same error and just changed the "date and time " of the windows from analog to automatic...

A Workflow Copilot. Tailored to You.

Pieces.app image

Our desktop app, with its intelligent copilot, streamlines coding by generating snippets, extracting code from screenshots, and accelerating problem-solving.

Read the docs

👋 Kindness is contagious

Engage with a sea of insights in this enlightening article, highly esteemed within the encouraging DEV Community. Programmers of every skill level are invited to participate and enrich our shared knowledge.

A simple "thank you" can uplift someone's spirits. Express your appreciation in the comments section!

On DEV, sharing knowledge smooths our journey and strengthens our community bonds. Found this useful? A brief thank you to the author can mean a lot.

Okay