Configuring AWS Elastic Beanstalk Timezone for Auto Scaling

6k views Asked by At

I have a single instance server deployed on AWS - Elastic Beanstalk that needs timezone configuration, and I changed the timezone as logging into the EC2 environment with ssh, and update it with the linux commands listed below;

sudo rm /etc/localtime
sudo ln -sf /usr/share/zoneinfo/Europe/Istanbul /etc/localtime
sudo reboot

Everything is fine as the server is running as a single instance. The problem arose as I wanted to use Auto Scaling, Load Balancing feature. On single instance, updating the timezone on linux AMI is fine, but on auto scaling mode, because that the instances are created/destroyed/recreated according to the threshold metrics, all the configuration is lost.

My simple question is, how can I change/configure the timezone for an auto scalable, load balancing mode in AWS Elastic Beanstalk ?

4

There are 4 answers

0
Tal On BEST ANSWER

you can configure the newly starting server with ebextensions.
Here's an example that works for me. Add the following command into the file .ebextensions/timezone.config:

commands:
    set_time_zone:
        command: ln -f -s /usr/share/zoneinfo/US/Pacific /etc/localtime 
1
Michael Hains On

For my first answer on StackOverflow ... I have to add new information to an excellent earlier answer.

For AWS Linux 2, Elastic Beanstalk, there is a new simple method of setting time. Add the following commands into the file .ebextensions/xxyyzz.config:

container_commands:
  01_set_bne:
    command: "sudo timedatectl set-timezone Australia/Brisbane"
    command: "sudo systemctl restart crond.service"

I'm not sure if the second command is absolutely essential, but the instances certainly play nice with it there (especially with tasks due to happen right away !).

1
Danny Yassine On

You can also configure it via ssh in the command line:

when connected to your Elastic Beanstalk Instance: http://docs.aws.amazon.com/AWSEC2/latest/UserGuide/set-time.html#change_time_zone

sudo ln -sf /usr/share/zoneinfo/America/Montreal /etc/localtime

You can connect to your EB instance with the eb command line tool. http://docs.aws.amazon.com/elasticbeanstalk/latest/dg/eb3-cmd-commands.html

eb ssh
0
Tikiboy On

The answers here only managed to work for me partially (I had errors deploying when using the answers above). After some modifications, the following worked for me. I believe it has something to do with "cwd" and "permissions".

commands:
  0000_0remove_localtime:
    command: rm -rf /etc/localtime
  0000_1change_clock:
    command: sed -i 's/UTC/Asia\/Singapore/g' /etc/sysconfig/clock
    cwd: /etc/sysconfig
  0000_2link_singapore_timezone:
    command: ln -f -s /usr/share/zoneinfo/Asia/Singapore /etc/localtime
    cwd: /etc