Written By:
7 minute read
Amazon S3Upload ErrorHow To

How to Resolve Amazon S3 File Upload Error - RequestTimeTooSkewed

Posted in Programming     AUGUST 27, 2018

If you upload your static resources like CSS, JS files or images/pictures uploaded by users to Amazon S3, then sooner or later you will encounter the RequestTimeTooSkewed Error. In our case, we experienced this error in our S3 upload script after 6 months of successful execution. Hence, it was more mind-boggling for us, as our script stopped working all of a sudden.

Upon investigation, we found the error returned by S3 to be,

Error executing "PutObject" on "https://s3.ap-south-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><HostId>NjGMaKjQC0n3t+mzNlAEkGvNT7alphdnCiZ/UaF8Qr4gJFv8X+A6YyFfgndEm62mjS+0CqeBPLU=</HostId></Error>

Our first response was, What the hell is this? Then upon researching, we found this.

What's the error?

Amazon S3 uses NTP to keep its system clocks accurate. NTP stands for Network Time Protocol, which provides a standard way of synchronizing computer clocks on servers. NTP can be installed and used to keep the server time accurate, synchronized with accurate atomic clocks located around the world.

So, due to an incorrect time setting on your server, you must be getting this error.

To correct this issue, you must set the correct time on your server. To check current time of Amazon S3 server, run the following command:

$ curl http://s3.amazonaws.com -v

And to check the time on your server, use the following command,

$ date

Now that you have inspected the time difference, how to correct it. There are two different ways to do so, either manually set your server time or use install NTP and use it.

Manually Correcting the Time and Timezone

Once you have checked the date and time on your server using the date command, you know that it is not correct. If the timezone is what you need but the time is incorrect, use the following command to set time.

date -s "17 AUG 2018 12:36:51"

And if the time is correct but the timezone is incorrect, then you can set the right timezone. First, use the following command to list down all the available time zones,

ls /usr/share/zoneinfo

Once you have finalized the timezone, copy its value from the list of zones, and run the following commands (The commands are for CentOS 6)

# remove current timezone

rm /etc/localtime

# create softlink with new zone

ln -s /usr/share/zoneinfo/Asia/Kolkata /etc/localtime

This will update your timezone.

Synchronizing time with NTP Server

Follow the following steps to successfully install the NTP server.

Start by checking if your server already has ntp program installed, run the following command:

which ntpupdate

If it's not available, then type in the below command to install ntp:

yum install ntp

Now open the ntp config file located in /etc/ntp.conf and add the following entries(remove the existing similar entries),

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

Now save the configuration file and run the following command to restart ntpd service:

$ service ntpd restart

Now try uploading files to Amazon S3. Voila! it should work. If this solution doesn't work for you, share your issue with us by commenting below.