How to deploy to Elastic Beanstalk (Part 1)

- By Abhijit Kini


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.

deploying your application to elastic beanstalk


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:

how to deploy to elastic beanstalk

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...


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

  1. Install the Elastic Beanstalk Command Line Interface (EBCLI) on your local machine.
    1. 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.
  2. Fork this simple Node.js application to your GitHub repository as shown below:

    Fork the sample nodejs application

Set up local Dev environment

  1. Clone your GitHub repository locally by running the following command:
    git clone --branch tutorial --single-branch nodejsapp
    where should be replaced by the fork you created in the previous step.
  2. In your Terminal, cd into the 'nodejsapp' directory.

Configure Elastic Beanstalk (EBS)

  1. From the 'nodejsapp' directory, run eb init command.
  2. Input values for the the following prompts that show up:
    1. Select a default region:Input the number closest to your region.
    2. Select an application to use:Input the default number to create a new application.
    3. Enter Application Name:Input sample-node-eb-paas-app
    4. It appears you are using Node.js. Is this correct?Input y
    5. Do you want to set up SSH for your instances? Input n
  3. Now let's create your running environment by running eb createcommand.
  4. Input values for the the following prompts that show up:
    1. Enter Environment Name:Input sample-node-eb-paas-env
    2. Enter DNS CNAME prefix:Hit 'Enter' for the default option.
    3. 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

  1. From the 'nodejsapp' directory, run the eb deploy command to deploy the application to Elastic Beanstalk.
    1. 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.
    2. NOTE: It is important to understand that the above command will provision Elastic Beanstalk resources on AWS and you may incur charges.

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

Configure your Shippable environment

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

      Enable a project

    4. 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.

      Project settings page

      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.

  2. 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.

    Adding AWS integration to the project

    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.

    Adding AWS integration in account settings
  3. Create ashippable.yml file in your local 'nodejsapp' directory.
  4. For this tutorial, populate the shippable.yml with the syntax given below.
      1. 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
      - "5.3"
      firefox: "23.0"
      - selenium
        - sudo npm install
        - export DISPLAY=:99.0
        - xvfb-run --server-args="-ac" npm test
        - 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
  5. 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)
    • 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
  6. 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.
  7. Let us now verify the above step:
    1. In your local machine Terminal & within the 'nodejsapp' directory, run the eb status command.
    2. Pay particular attention to Deployed Version field as shown below:

      deployed version on elastic beanstalk

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

      deployed version on elastic beanstalk console
    4. Now, go into the Shippable portal & access the build that successfully completed within the sample_node_eb_paas Project
    5. Click on the 'tutorial' build. Within the 'Console' tab, click on aws_eb_paas_deploy. Expand the eb deploy
    6. 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:

      deployed version of application on elastic beanstalk on Shippable

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.

  1. In your local nodejsapp directory, go into the 'public' folder & open index.html.
  2. 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'.
  3. Save the files & push the changes to your GitHub repository 'sample_node_eb_paas'.
  4. The commit action in yourGitHub sample_node_eb_paas repository will trigger the following withinShippable:
    1. Triggers a build automatically within the Shippable portal, by syncing with your GitHub repository.
    2. 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.
    3. Installs Elastic Beanstalk Command Line Interface (CLI) required to update your source code on Elastic Beanstalk.
    4. Authenticates into the Elastic Beanstalk console using the AWS credentials you have configured.
    5. Zips your application files in your repository.
    6. Uploads the zipped files to Amazon S3 for Elastic Beanstalk to access.
    7. Issues the Deploy command on Elastic Beanstalk from the right directory.
  5. A successful build will be seen within the Shippable portal as shown:

    successful build on Shippable

  6. Verify the updates have been successfully deployed to your Elastic Beanstalk application for your end users:
    1. In your Terminal, within the nodejs directory, execute the eb open command.
    2. The web page is updated to show the below picture

Successful deployment of application on elastic beansalk

Wrap up


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.

Try Shippable

Topics: Elastic Beanstalk, AWS