Why Cloud Time Is Different
Virtual machines in the cloud face unique timekeeping challenges. The hypervisor can pause, migrate, or snapshot a VM without the guest OS knowing, causing the guest clock to drift by seconds or even minutes in extreme cases. Cloud providers build specialized time infrastructure to address this.
AWS: Amazon Time Sync Service
AWS provides a fleet of stratum 1 NTP servers accessible from any EC2 instance at the link-local address 169.254.169.123. These are connected to GPS and atomic clocks in each AWS region and use leap second smearing.
# /etc/chrony.conf on Amazon Linux / Ubuntu on EC2
server 169.254.169.123 prefer iburst minpoll 4 maxpoll 4
# Amazon's NTP is Stratum 1 connected to GPS
# Check sync status
chronyc tracking
# Reference ID: 169.254.169.123 (Amazon Time Sync)
# Stratum: 2 ← your instance is Stratum 2
# AWS also offers PTP (requires network driver support)
# Uses: 169.254.169.123 over UDP port 319/320
Google Cloud: Google Public NTP
GCP instances should sync to metadata.google.internal (169.254.169.254) or use the public Google NTP servers:
# /etc/chrony.conf on GCP VM
server metadata.google.internal iburst
# Or use public Google NTP
server time.google.com iburst
server time2.google.com iburst
server time3.google.com iburst
server time4.google.com iburst
# Google NTP features:
# - Stratum 1, connected to GPS + atomic clocks
# - Leap second smearing over 20-hour window
# - Anycast routing to nearest Google data center
Azure: Windows Time Service and Chronyd
# Azure VMs (Windows) use Windows Time Service (W32TM)
w32tm /query /status
w32tm /config /manualpeerlist:"time.windows.com" /syncfromflags:manual
# Azure Linux VMs — use the Azure NTP service
# Built into Azure Fabric (host-based time sync)
server 168.63.129.16 iburst # Azure's time server
Container and Kubernetes Time
Containers share the host kernel's clock — they cannot sync independently. Ensure your EC2 instance / GCP VM / Azure VM is properly synced, and all containers inherit accurate time:
# Docker: containers inherit host clock
docker run alpine date # same as host
# Kubernetes: pods use node's time
# Ensure node is synced before scheduling time-sensitive workloads
# Check node time sync in Kubernetes
kubectl get nodes -o wide
kubectl debug node/my-node -it --image=alpine -- chronyc tracking
Serverless and Lambda Time
AWS Lambda, Google Cloud Functions, and Azure Functions run in managed execution environments synced by the cloud provider. You don't manage NTP for serverless — the environment is synced. However, cold start latency means the first function invocation may have a slightly stale clock if the container was paused:
# In Lambda, always use time from the runtime (synced)
import time
print(time.time()) # Accurate — Lambda runtime is synced
Best Practices for Cloud Time
- Use the cloud provider's local NTP endpoint (169.254.169.123 for AWS) — it's the most accurate and lowest latency
- Set
minpoll 4 maxpoll 4for aggressive syncing on EC2 (poll every 16 seconds) - Enable the cloud provider's time sync service (e.g.,
amazon-ssm-agenton Amazon Linux) - Monitor
chronyc trackingfor offset and ensure it stays under 10ms