Ticker

6/recent/ticker-posts

How to change the default timezone and nginx configuration in AWS Elasticbeanstalk

Prerequisite: ElasticBeanstalk

Usecase: 

Application code was using default server timezone and requirement was to have specific timezone in place and application was hosted on AWS PAAS i.e elasticbeanstalk.



There are two ways that you could run custom script on elasticbeanstalk platform before the deployment[1].

  1. Platform hook scripts
  2. .ebextensions configuration file

I am going to use .ebextensions configuration file in order to run the custom script which is going to do the following things.
  • It will change the default timezone to US/Eastern timezone


Application source bundle:

.
├── .ebextensions
│   └── timezone.config
│   └── nginx-settings.config
├── .elasticbeanstalk
│   └── config.yml
├── .gitignore
├── app.js
├── cron.yaml
├── index.html
└── package.json


The contents of 'timezone.config' should be as follows in YAML format :

commands:
  command block:
    command: |
        link=$(readlink -f /etc/localtime)
        if [[ $link != "/usr/share/zoneinfo/US/Eastern" ]]; then
          ln -f -s /usr/share/zoneinfo/US/Eastern /etc/localtime
          echo "Time Zone US/Eastern"
        fi


The contents of 'nginx-settings.config' should be as follows in YAML format :

files:
  "/etc/nginx/conf.d/nginx-settings.conf":
      mode: "00644"
      owner: "root"
      group: "root"
      content: |
        client_max_body_size 10M;

container_commands:
  01_restart_nginx:
    command: "sudo service nginx restart"


And now after ziping the .ebextension folder along with code deploy it to elasticbeanstalk.
Happy cloud computing!!



References:

[1] https://docs.aws.amazon.com/elasticbeanstalk/latest/dg/custom-platforms-scripts.html

Post a Comment

0 Comments