Ubuntu EC2 configure Amazon Time Sync Service for Amazon AWS

Having problems keeping your server time in sync? or a project requiring accurate timing? If your using a Amazon EC2 instance you can swap to using Chrony and Amazon Time Sync using the below commands.

Code is provided as is, I cannot be helf responsible for any issues which may occur

The Problem

Today I ran into an issue where a Laravel project hosted on an Amazon EC2 instance was creating records, but the created_at time stamps where in the wrong order. For example

1st record -> 12/12/2020 10:30:20
2nd record -> 12/12/2020 10:30:10

Record two occured after the 1st record but had a timestamp indicating otherwise. After some research I found the time sync service on the server from a fresh install was “timesyncd”, and had up to a 30 minute delay between syncing with the time server, this could allow the server to become out of sync and in this case, the time sync updated during the period between the two records being created, causing the 2nd record to have a timestamp before the first record.

Chrony & Amazon Time Sync

Chrony is a time sync service based on an improved NTP technology, lucky amazon offers a time sync service which had very regular check intervals minimising the chances of the servers time becomine out of sync. I create a simple script below which can be used on a fresh EC2 server with Ubuntu to swap to Chrony and implement the Amazon Time Sync config.

Read more about Amazon Time Sync Service on the Amazon AWS website

https://aws.amazon.com/about-aws/whats-new/2017/11/introducing-the-amazon-time-sync-service/

 

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.