AWS Elastic Beanstalk

5 April 2016 by Rohinee Matale No comments

AWS Elastic Beanstalk is a PaaS (Platform as a Service) offered from Amazon Web Services with which you can quickly deploy and manage applications in the AWS.

» Services with ElasticBeanstalk : 
1. An Amazon S3 bucket to store environment data and application versions.

a. Environment Data : Elastic Beanstalk creates a new application in which we can create               multiple environments. Each environment has different security group. ElasticBeanstalk has       “environments” bucket in S3 which contain folders according to application’s environment            name and each of it has a compressed code of latest version.
b. Application version : ElasticBeanstalk creates a folder with the name same as of the last commit and uploads files on S3.

2. A load balancer to distribute traffic to the web server(s).

Elastic Beanstalk allows you to create any one of:
a. Load-balancing, autoscaling environment
b. Single-instance environment

3. A security group to allow incoming web traffic.

Elastic Beanstalk creates a default security group. Security group name is visible in the EC2 under Security Groups column.

4. Amazon CloudWatch alarms that notify the Auto Scaling group when the load is low or high.

Amazon CloudWatch alarms help you implement decisions more easily by enabling you to send notifications or automatically make changes to the resources you are monitoring, based on rules that you define.

5. An Auto Scaling group  to adjust the number of servers in response to load changes.

By default, ElasticBeanstalk creates 2 – 4 instances if a user has created an environment with load balancing, autoscaling option.

» Deployment with ElasticBeanstalk
Amazon has given nice document for deployment process and also check this for /.ebextensions configuration

» What happens in the process of Deployment?
1. Elastic beanstalk uploads the code with the latest commit to the S3 in the bucket which has the same name as your application. If the application does not have any new commits, then it considers the files of the last commit. It also updates environment data and application versions.

2. InfraWriteConfig :

It generates –
a) appsourceurl file at /opt/elasticbeanstalk/deploy/configuration/appsourceurl. – S3 url of the latest version of the code.
b) containerconfig file at /opt/elasticbeanstalk/deploy/configuration/containerconfiguration. – contains commands to be executed in the deployment process.

3. InfraWriteApp1 : It (re)creates /opt/elasticbeanstalk/deploy/appsource which contains “source_bundle” file in encrypted format.

4. InfraWriteApp2 : Elasticbeanstalk downloads a manifest file from S3 which contains deployed version number followed by latest version uploaded on S3. These both files are present in environments folder of S3. ElasticBeanstalk also downloads hook files from S3 which contains script files & .sh files to setup environment_variable and do the deployment.

5. Then setup EbExtensionPreBuild :

It adds package and update or create files if you have mentioned in /.ebextensions folder
a. prebuild_0_<application> – it install packages which you have mentioned in /.ebextensions/01packages.config file of ruby app
b. prebuild_n_<application> – creates multiple prebuild tasks depends on the ‘Files’ you have mentioned in /.ebextensions.

6. AppDeployPreHook :

ElasticBeanstalk deploys code in /var/app/deck folder first and does all rails operation. This folder then moved to current. This folder is considered as EB_APP_STAGING_DIR
a. unzip – Unzip folder downloaded from S3.
b. setup_envvars – Get environment_variable and load it to envvar file
c. bundle_install :

i. Load environment_variable
ii. Set ruby-version
iii. Get list of gems (check-for-gem.rb)
iv. move to EB_APP_STAGING_DIR & Do bundle install
v. Change ownership of Gemfile.lock

d. asset_compilation –

i. Load environment_variable
ii. Set ruby-version
iii. get a list of rake tasks (check-for-rake-task.rb)
iv. move to EB_APP_STAGING_DIR & do assets:precompile

e. db_migration –

i. Load environment_variable
ii. Set ruby-version
iii. get a list of rake tasks (check-for-rake-task.rb)
iv. move to EB_APP_STAGING_DIR & do rake:db_migration

f. test_for_puma –

i. Load environment_variable
ii. Set ruby-version
iii. Get a list of gems to be install (check-for-gem.rb) and look for puma gem
iv. update /etc/elasticbeanstalk/has_puma.txt according to availability of gem

7. EbExtensionPostBuild :

It adds container commands from “.ebextensions/05container_commands.config” to create “postbuild_n_<application_name>” and executes it.

8. InfraCleanEbextension :

Remove .ebextensions folder from EB_APP_STAGING_DIR

9. AppDeployEnactHook :

a. Flip Folders

i. move /var/app/current directory to /var/app/current.old
ii. move /var/app/ondeck to /var/app/current
iii. change ownership of /var/app/current folder.
iv. remove /var/app/current.old

b. Restart puma server

10. AppDeployPostHook :

Run .sh files of postdeploy hooks. Delayed_job example with postdeploy script.

Rohinee Matale

Follow me on Twitter

Leave a Reply

Your email address will not be published. Required fields are marked *

Subscribe To Our Blog

Get access to proven marketing ideas, latest trends and best practices.

Next up home


Lets build cool stuff

Share your contact information & we will get in touch!

I want (Tell us more about your dream project)