This morning I was about to kickoff some typical jobs with AWS CLI on an Linux EC2 instance. The AWS CLI command always raised the error,

1
2
3
[user@host ~]$ aws s3 ls

An error occurred (RequestTimeTooSkewed) when calling the ListBuckets operation: The difference between the request time and the current time is too large.

even with the simplest list object command the error were still there!!!

what???

By querying Stack Overflow, some people had the same problem with S3 upload, and suggested to compare the local time with Amazon server-side time.

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
[user@host ~]$ curl http://s3.amazonaws.com -v
* Rebuilt URL to: http://s3.amazonaws.com/
*   Trying 52.216.109.245...
* TCP_NODELAY set
* Connected to s3.amazonaws.com (52.216.109.245) port 80 (#0)
> GET / HTTP/1.1
> Host: s3.amazonaws.com
> User-Agent: curl/7.53.1
> Accept: */*
>
< HTTP/1.1 307 Temporary Redirect
< x-amz-id-2: v+RgpF1hAf6/OcevN+vUQbt7bdEAS98dOqfTx72Le/7SHHSzN14ZDKS2l0d/E9N9nPQRemFiFa0=
< x-amz-request-id: 2C1CC23AA13423D3
< Date: Sat, 02 Feb 2019 18:53:17 GMT
< Location: https://aws.amazon.com/s3/
< Content-Length: 0
< Server: AmazonS3
<
* Connection #0 to host s3.amazonaws.com left intact
[user@host ~]$ date -u
Sat Feb  2 19:09:17 UTC 2019

Somehow the EC2 instance dropped into the wormhole and became a Time Traveler! Well done, time traveler!


Typically, there are two ways to sync time between instance local and the server:

  • ntp
  • chrony

ntp

If your server already had ntp installed, the you can direct modify the /etc/ntp.conf file by adding

1
server 169.254.169.123 iburst

And then restart your ntp service via

1
sudo service ntpd restart

Sometime the ntp service is named as ntp, so the command will be like sudo service ntp restart.

The followings was just the termial log of the above operations.

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
[user@host ~]$ date -u
Sat Feb  2 19:12:22 UTC 2019
[user@host ~]$ sudo vim /etc/ntp.conf
[user@host ~]$ sudo service ntpd restart
Shutting down ntpd:                                 [  OK  ]
Starting ntpd:                                      [  OK  ]
[user@host ~]$ sudo service ntpd status
ntpd (pid  20685) is running...
[user@host ~]$ date -u
Sat Feb  2 18:59:18 UTC 2019

and there is no time difference between the server and local.

chrony

Another suggested way is to use chrony package instead of using ntp. AWS already have chrony built-in the AWS Linux 2 AMI so you don’t need to install chrony if you are using Linux 2 AMI like me.

The solution with chrony is quite similar like ntp, what we need to do is to modify the /etc/chrony.conf file by adding

1
server 169.254.169.123 prefer iburst

Then you need to restart the chrony service to let it pick up the latest configuration.

1
sudo service chrony restart

Same with npt, the chrony service may also named as chronyd.

Hope this helps.

tada

Reference