3

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 ?

Levent Divilioglu
  • 9,139
  • 5
  • 49
  • 96
  • The thing making this hard is the `sudo reboot `. I don't think you need it. There should be a way to restart the clock service. Assuming you can, you can do all this by using an ebextension config file – Nick Humrich Jun 19 '15 at 20:14

4 Answers4

11

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 
Tal
  • 7,136
  • 5
  • 32
  • 58
2

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
Tikiboy
  • 812
  • 8
  • 17
0

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

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
Danny Yassine
  • 602
  • 7
  • 9
  • The only problem with this solution is that it is not sustainable. If your Elastic Beanstalk instances are rebuilt (or your app auto-scales), the new instances will not automatically be configured and require the manual `ssh` intervention prescribed. The `.ebextensions` answer from @tal is automatic and lives in your app's configuration. – Dan Mar 07 '17 at 18:26