How to deploy to Elastic Beanstalk (Part 1)

- By Abhijit Kini on March 28, 2016

AWS Elastic Beanstalk (EBS) is an easy-to-use service for deploying and scaling web applications and services developed with Java, .NET, PHP, Node.js, Python, Ruby, Go, and Docker on familiar servers such as Apache, Nginx, Passenger, and IIS. With AWS Elastic Beanstalk, you can quickly deploy and manage applications in the AWS cloud without worrying about the infrastructure that runs those applications. AWS Elastic Beanstalk reduces management complexity without restricting choice or control. You simply upload your application, and AWS Elastic Beanstalk automatically handles the details of capacity provisioning, load balancing, scaling, and application health monitoring.

Shippable's unified CI/CD platform enables you to deploy your application to various Platform as a Service (PaaS) and Infrastructure as a Service (IaaS) providers, such as AWS Elastic Beanstalk, as part of the end to end continuous deployment platform offered by Shippable.

In the first part of this two part series, we will go through source code deployment of a Node.js application to AWS Elastic Beanstalk. In the second part, we will go through deploying a Docker container of a Node.js application to AWS Elastic Beanstalk.

Source Code deployment to AWS Elastic Beanstalk

To understand the benefits of Shippable's AWS Elastic Beanstalk integration, we will first create a simple Node.js application & deploy it to AWS Elastic Beanstalk. Then we will go through configuring Shippable to automatically execute certain actions for you in the background, and update your source code application on Elastic Beanstalk.The overview of the tutorial work flow shown is below:

The specific actions that Shippable automatically triggers to deploy your application to Elastic Beanstalk, after a successful CI build, are:

Installs Elastic Beanstalk Command Line Interface (CLI)

Authenticates into the Elastic Beanstalk console using the right credentials

Zips your application files

Uploads to Amazon S3

Issues the Deploy command on Elastic Beanstalk from the right directory

In order for Shippable to perform the above actions, you will need to configure Shippable, for a successful deployment to Elastic Beanstalk.

It is important that you complete the deployment of the sample Node.js application on Elastic Beanstalk first and then configure Shippable to automate tasks to updated your application. This approach will give you a good understanding of the clear delineation of what Shippable does automatically behind the scenes and what occurs outside of that context.

Set up local Dev environment

Clone your GitHub repository locally by running the following command:git clone git@github.com:abhijitkini/sample_node_eb_paas.git --branch tutorial --single-branch nodejsappwhere git@github.com:abhijitkini/sample_node_eb_paas should be replaced by the fork you created in the previous step.

In your Terminal, cd into the 'nodejsapp' directory.

Configure Elastic Beanstalk (EBS)

From the 'nodejsapp' directory, run eb init command.

Input values for the the following prompts that show up:

Select a default region:Input the number closest to your region.

Select an application to use:Input the default number to create a new application.

This will take you to the sample_node_eb_paas project page as shown below. You will see a 'master' and a 'tutorial' branch. We are working off the 'tutorial' branch.

NOTE: If you trigger the build manually at this point, by clicking the 'Build' button, it will fail with the error failed to find shippable yml file. The reason is because we have not completed the needed configurations.

Go to the 'Settings' tab within the sample_node_eb_paas Project page. Click on the 'Select a deploy integration' drop down & select your existing AWS integration as shown below.

integrationName: replace "AWS-Abhijit" with your Account Integration in Shippable, set up for AWS (keep the double quotes)

platform: replace 'Node.js' with your platform (available options can be found here)

application_name: replace only if you have given a different application name

env_name: replace only if you have given a different environment name

region: replace with your Elastic Beanstalk region name

Push the newly created shippable.yml local file to your GitHub repository by running the following commands in your Terminal from your local 'nodejsapp' directory:

git add .

git commit -m "added shippable.yml"

git push origin tutorial

As mentioned above, we are working on the 'tutorial' branch of the 'master'. This action will trigger a build within Shippable and successfully deploy your application to Elastic Beanstalk.

Let us now verify the above step:

In your local machine Terminal & within the 'nodejsapp' directory, run the eb status command.

Pay particular attention to Deployed Version field as shown below:

You can also view the deployed version of this application from the AWS Elastic Beanstalk console.

Now, go into the Shippable portal & access the build that successfully completed within the sample_node_eb_paas Project

Click on the 'tutorial' build. Within the 'Console' tab, click on aws_eb_paas_deploy. Expand the eb deploy

Verify the application version. It matches with what was deployed in Elastic Beanstalk, as shown below. You have successfully completed continuous integration for AWS EBS:

Update the source code and have Shippable deploy changes on Elastic Beanstalk

Now that you have configured Shippable to deploy updates on Elastic Beanstalk for you, let's make an update to your application & watch how fast Shippable's automation will deploy the update and make it available to your end users.

In your local nodejsapp directory, go into the 'public' folder & open index.html.

Authenticates into the Elastic Beanstalk console using the AWS credentials you have configured.

Zips your application files in your repository.

Uploads the zipped files to Amazon S3 for Elastic Beanstalk to access.

Issues the Deploy command on Elastic Beanstalk from the right directory.

A successful build will be seen within the Shippable portal as shown:

Verify the updates have been successfully deployed to your Elastic Beanstalk application for your end users:

In your Terminal, within the nodejs directory, execute the eb open command.

The web page is updated to show the below picture

Wrap up

Congratulations!

You have successfully enabled Shippable to automate repetitive developer tasks and update your Node.js application to deploy to Elastic Beanstalk as a frictionless deployment. Depending on your automated tests and deployments scenarios, you can perform customization by configuring Elastic Beanstalk directly, outside of Shippable. Shippable will continue to automatically trigger deployments into Elastic Beanstalk upon a successful Shippable CI build and help you ship code faster.

Additional resources on this topic:

Documentation on deploying your application to various PaaS/IaaS providers

A tutorial by Amazon on deploying an Express Application to Elastic Beanstalk