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.

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.

Nice. It matches with the output of date

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

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.

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

Some weird

And some quotes

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