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.

Let's jump right in...

Prerequisites

To get started, you need to have (or obtain):

An AWS account to deploy applications on AWS Elastic Beanstalk

A source control account (GitHuborBitbucket) For this tutorial, we'll use GitHub

A Shippable account This can be done by simply logging into Shippable using your source control credentials (GitHub/Bitbucket, etc.)



Set up Git Repository

Install the Elastic Beanstalk Command Line Interface (EBCLI) on your local machine. Verify that the EBCLI is installed correctly by running the eb --version command. You should see EB CLI 3.2.2 (Python 3.4.3) as a result. Fork this simple Node.js application to your GitHub repository as shown below:





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 nodejsapp

where 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. Enter Application Name: Input sample-node-eb-paas-app It appears you are using Node.js. Is this correct? Input y Do you want to set up SSH for your instances? Input n Now let's create your running environment by running eb create command. Input values for the the following prompts that show up: Enter Environment Name: Input sample-node-eb-paas-env Enter DNS CNAME prefix: Hit 'Enter' for the default option. Wait for a few minutes until the environment has been created and you are back to the prompt in your Terminal.

Deploy and View the Application

From the ' nodejsapp ' directory, run the eb deploy command to deploy the application to Elastic Beanstalk. This process may take several minutes to complete. Elastic Beanstalk will provide status updates during the process. Once done, you'll see a similar picture as shown below. NOTE: It is important to understand that the above command will provision Elastic Beanstalk resources on AWS and you may incur charges.



From the ' nodejsapp ' directory, run the eb open command to view the application in your browser. Next, let's configure the Shippable environment & have Shippable automatically trigger the deployment to Elastic Beanstalk upon successful CI build.

Configure your Shippable environment

Login to Shippable and create a project by accessing the'CI' tab and clicking the 'Enable Project' button. View the list of projects & look for sample_node_eb_paas. If it does not show up in the list, type sample_node_eb_paas & click the 'Sync' button as shown in the picture. Click 'Enable' for sample_node_eb_paas thereby enabling your GitHub repository within Shippable.







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.







NOTE: If you have not configured an AWS integration within Shippable, then go into the 'Account Settings' & click 'Add Integration' to configure the AWS integration. For additional help, refer to the detailed steps of configuring AWS integration within Shippable.



Create a shippable.yml file in your local 'nodejsapp' directory. For this tutorial, populate the shippable.yml with the syntax given below. Outside of this tutorial, you would populate the shippable.yml file with your details per the scenario you use. A detailed guide to the yml format can be referenced for customizing per your scenario. # Language setting language: node_js # Version number node_js: - "5.3" addons: firefox: "23.0" services: - selenium build: ci: - sudo npm install - export DISPLAY=:99.0 - xvfb-run --server-args="-ac" npm test integrations: deploy: - integrationName: "AWS-Abhijit" type: aws target: eb_paas platform: "Node.js" application_name: sample-node-eb-paas-app env_name: sample-node-eb-paas-env region: us-west-2 Replace the following values in the above form, with your values: integrationName : replace "AWS-Abhijit" with your Account Integration in Shippable, set up for AWS (keep the double quotes)

: 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)

: replace 'Node.js' with your platform (available options can be found here) application_name : replace only if you have given a different application name

: replace only if you have given a different application name env_name : replace only if you have given a different environment 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. Replace 'You have successfully deployed this NodeJS test app to AWS Elastic Beanstalk' with 'You have successfully updated this NodeJS test app on AWS Elastic Beanstalk using Shippable'. Save the files & push the changes to your GitHub repository 'sample_node_eb_paas'. The commit action in yourGitHub sample_node_eb_paas repository will trigger the following withinShippable: Triggers a build automatically within the Shippable portal, by syncing with your GitHub repository. Performs Continuous Integration for Elastic Beanstalk - your code will be automatically built, tested and you will receive a notification with build results in the build console. Installs Elastic Beanstalk Command Line Interface (CLI) required to update your source code on Elastic Beanstalk. 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

Next, let's look at deploying a Docker container of a Node.js app on AWS Elastic Beanstalk, the part 2 of this CI/CD pipelines for EBS series.