Setting a specific timezone in AWS Fargate

Image by Pexels on Pixabay

AWS Fargate removes the need to provision and manage services.

When sending mails with Amazon SES the mail will have a sent date. Example: A german user triggers something at 3 PM Berlin time. That in turn sends a mail. Could be a password reset.

Without changes in the timezone the mail will have a sent time before 3 PM when viewed by the german. For example 1 PM during daylight savings time. Unnecessary confusion for the user.

Why? Because the host is using UTC. Fine in general. When having a service only used by germans we could switch the timezone to Europe/Berlin

If we want to set the timezone on EC2 we would change it in the host (e.g. AWS Linux). In AWS Fargate we can do it on the host level too. On the Docker container.

If we have no access to the container there are ways to to set it in the code.
The following sets the timezone in a Kotlin codebase.

Using Europe/Berlin instead of specific GMT+1 or GMT+2 to take into account daylight savings time automatically.

A list of timezones can be found here.

The alternative is to set it on the container by adding the following. The example would extend openjdk:14-jdk-alpine

Done.

We can verify whether it works with running bash in the container and overwriting the entry point with --entrypoint /bin/sh

There are multiple ways to make this work. The above offers two.

Our issue is fixed. Though we could dive deeper into tzdata if we want to.

Down the rabbit hole

If we attempt to check what the contents of /etc/localtime is the output will not be readable. We can apply the command line tool utility zdump. Short for timezone dumper.

zdump /etc/localtime
/etc/localtime Sun Jul 12 11:08:54 2020 CEST

Nice. It matches with the output of date

date
Sun Jul 12 11:08:54 CEST 2020

If we use zdump with -v we get the info on when the times switch between daylight savings time and back until the year 2499

The following is an example for Europe/Berlin

Sun Mar 29 00:59:59 2499 UT = Sun Mar 29 01:59:59 2499 CET isdst=0 gmtoff=3600
Sun Mar 29 01:00:00 2499 UT = Sun Mar 29 03:00:00 2499 CEST isdst=1 gmtoff=7200
Sun Oct 25 00:59:59 2499 UT = Sun Oct 25 02:59:59 2499 CEST isdst=1 gmtoff=7200
Sun Oct 25 01:00:00 2499 UT = Sun Oct 25 02:00:00 2499 CET isdst=0 gmtoff=3600

In 2499 on Sunday, March the 29th at 2 AM the clocks will be moved forward one hour to CEST. isdst=1 means daylight savings time is true. On Sunday, October the 25th at 3 AM the clock will be moved back one hour to CET.

Some trivia

When spelunking around the repo for tz

[…] compendium of data about the history of civil time […]

We find a file for europe.

Some interesting contents

# From Jörg Schilling (2002-10-23):
# In 1945, Berlin was switched to Moscow Summer time (GMT+4) by
# https://www.dhm.de/lemo/html/biografien/BersarinNikolai/
# General [Nikolai] Bersarin.

Some weird

# From Paul Eggert (2004-10-31):
# During World War II, Germany maintained secret manned weather stations in
# East Greenland and Franz Josef Land, but we don't know their time zones.
# My source for this is Wilhelm Dege's book mentioned under Svalbard.

And some quotes

# From Winston Churchill (1934-04-28):
# It is one of the paradoxes of history that we should owe the boon of
# summer time, which gives every year to the people of this country
# between 160 and 170 hours more daylight leisure, to a war which
# plunged Europe into darkness for four years, and shook the
# foundations of civilization throughout the world.
# -- "A Silent Toast to William Willett", Pictorial Weekly;
# republished in Finest Hour (Spring 2002) 1(114):26
# https://www.winstonchurchill.org/publications/finest-hour/finest-hour-114/a-silent-toast-to-william-willett-by-winston-s-churchill

Building things. Usually by writing code. www.hodler.co. Software Engineering @porschedigital

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store