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,
|
|
even with the simplest list object command the error were still there!!!
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.
|
|
Somehow the EC2 instance dropped into the wormhole and became a 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
|
|
And then restart your ntp service via
|
|
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.
|
|
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
|
|
Then you need to restart the chrony service to let it pick up the latest configuration.
|
|
Same with npt, the chrony service may also named as chronyd
.
Hope this helps.