Signup/Sign In

How to Resolve Amazon S3 File Upload Error - RequestTimeTooSkewed

Posted in Programming   LAST UPDATED: JULY 11, 2023

    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 suddenly stopped working.

    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 RequestTimeTooSkewed?

    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 the current time of the 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.


    How to Resolve Amazon S3 File Upload Error - RequestTimeTooSkewed

    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 control to set the 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 time zone.


    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.

    Conclusion

    Okay then, You surely know the troubleshooting techniques to overcome the RequestTimeTooSkewed error when uploading files to Amazon S3. By understanding the causes of this issue, adjusting your system's clock, configuring NTP synchronization, and verifying AWS region settings, you can ensure proper time synchronization and seamless file uploads to S3.

    Frequently Asked Questions(FAQs)

    What does the "RequestTimeTooSkewed" error in Amazon S3 mean?

    The "RequestTimeTooSkewed" error occurs when there is a significant time difference between the client making the file upload request and the server time maintained by Amazon S3. It indicates a time synchronization issue and prevents successful file uploads.

    What can cause the "RequestTimeTooSkewed" error in Amazon S3?

    The error can be caused by incorrect system clock settings on the client machine, network latency, incorrect time zone configuration, or mismatches in AWS region settings.

    How can I resolve the "RequestTimeTooSkewed" error in Amazon S3?

    To resolve the error, you can start by ensuring that the system clock on the client machine is accurate and synchronized with a reliable time source. Additionally, configuring Network Time Protocol (NTP) synchronization and verifying the AWS region settings can help resolve the time skew issue.

    How do I synchronize the system clock with a reliable time source?

    On most operating systems, you can configure the system clock to synchronize with a reliable time source using Network Time Protocol (NTP). This protocol enables automatic time synchronization with public NTP servers or internal time servers within your network.

    What should I do if the "RequestTimeTooSkewed" error persists after time synchronization?

    If the error persists, ensure that the AWS region settings on the client machine and in the S3 configuration are aligned. The region settings should be consistent across all components involved in the file upload process, including the client SDK, AWS CLI, and AWS Management Console.

    You may also like:

    About the author:
    I like writing content about C/C++, DBMS, Java, Docker, general How-tos, Linux, PHP, Java, Go lang, Cloud, and Web development. I have 10 years of diverse experience in software development. Founder @ Studytonight
    Tags:erroramazon-linux
    IF YOU LIKE IT, THEN SHARE IT
     

    RELATED POSTS