Skip to content

Building And Deploying Web Apps Into AWS Cloud Using AWS Elastic Beanstalk

phpjagadeesh edited this page Dec 4, 2014 · 142 revisions

This guide shows you how to deploy and manage web apps in Amazon Web Services (AWS) cloud platform using AWS Elastic Beanstalk. You will learn how to:

  • Create web app in AWS with AWS Elastic Beanstalk
  • Deploy web apps into AWS using AWS Elastic Beanstalk
  • Monitor web apps in AWS
  • Auto scaling web apps in AWS

###Table of Contents

##Introduction Platform as a Service (PaaS) model in the Cloud platforms, provide the capability to quickly build apps in the Cloud, in which you can easily manage, monitor and auto scale your apps. AWS Elastic Beanstalk is the PaaS offering from AWS which allows you to deploy your web apps into the AWS Cloud, whereby you don't have to worry about setting up the virtual machines from your end. The real power of the Cloud is the operation agility provided by the Cloud platform, where customer can just focus on building apps instead of spending time for setting up IT infrastructure. The PaaS model provides the real operational agility to Cloud apps.

## What is Elastic Beanstalk AWS Elastic Beanstalk is an easy to use amazon service for deploying and scaling web applications in AWS Cloud. Elastic Beanstalk provides support for Java, .NET, PHP, Node.js, Python, Ruby and Docker and very familiar web server like Apache, Nginx, Passenger, and IIS.

You can simply upload your code which was developed in your favorite language like PHP, JAVA or any other language and Elastic beanstalk automatically handles the deployment, load balancing and auto-scaling to application health monitoring. At the same time you should have full control over your application.
Elastic beanstalk is not separate technology from Amazon but it bring together the traditional component from EC2,S3,RDS and Cloudwatch in scalable infrastructure.

If you are using IDE like Visual studio or Eclipse then it is great news for you. These two IDE provides integrate tool for deploy and manage your application within in these IDE. But if you are using other tools then don’t worry! Amazon provides good SDK kit for you.

## Why Elastic Beanstalk In web world, there are number of option for deploying web applications. But deploying scalable application can bring some complexities. You need to solve these complexities yourself. But Elastic Beanstalk replaces these headaches with some clicks. Elastic Beanstalk provides complete scalable solutions without manual configurations.

A scalable web application bring additional resources automatically rather than manual configuration. These scalable infrastructures include application servers, Database servers, load balancer, log aggregation, firewall, monitoring, and alerting.

####Elastic Beanstalk provides number of benefits both in technical and business areas.
#####(1) Elastic Beanstalk simple to use Elastic beanstalk is pretty straight forward. Amazon provides Management console, Command line interface (CLI) or IDE such as Visual studio and Eclipse to upload your application. Elastic beanstalk is the fastest and simplest way to deploy your application. #####(2)Auto scaling facility According to your needs, Elastic Beanstalks scale your application up and down instead of manual configuration. #####(3)Fastest productivity You can concentrate only to your writing code not for configuration because Elastic Beanstalk will manage all these things .So time spending for configuration will reduce. #####(4)Full control over resources You can easily implement Amazon provides resources and your own resources without any barrier.

##Deploy web Apps in Elastic Beanstalk Amazon provides different method to deploy your application. These are #####(1) Use Amazon management console #####(2) Command Line interface #####(3) Integrated tool with Visual studio or Eclipse

Let’s move detail view in each deploying method. ####Use Amazon management console Before doing anything in amazon you need amazon account. If you already have amazon account skip this link. Sign up here

Now we have amazon account .Let’s move to management console page.

Step 1: This is the entry point of your Elastic Beanstalk. Here the list showing different services provided by amazon. Click the Elastic beanstalk from the below list.

Management console
Then it will redirect to next page as showing on step2.

Step 2: In this section you need to deploy a sample application. First ensure where you are standing either in United States, Singapore, Tokyo or Ireland. Region can easily find out from top right corner of management console page. Select any region as shown below.
Region
If any AWS Elastic Beanstalk applications already exist in the region in which you want to create and deploy an application, then jump to here. Else you can follow these steps.

If your application code is in PHP, then choose PHP platform or whatever you wish according to you application code. The screenshot is as follows.
Environment configuring If we are selecting our platform as PHP then the default running environment will be displayed under the dropdown box. Then we can easily change this environment by clicking the default link. When we click on the default link two more dropdown box will be displayed with version and load balancing or single instance technology. Image is as shown below.
Environment setup

Now ready to click on Launch Now button. But before click on this button you need some idea about two parameter Select version and Environment Type
.
The Select version drop down box contains the version of your programming language and which platform you need.
Depending on your application you can choose single instance or Load balancing-auto scaling instance. If your application is small and there is no traffic then single instance is enough .Otherwise depending on your application you can choose Load balancing. Single instance is low cost rather than load balancing.

Then click on Launch Now button.

After several minute environment will ready for use. Here some important action will going on after click on Launch Now button. The actions are:

  • Creating AWS Beanstalk application named My First Elastic Beanstalk Application.
  • Creating new Sample Application in this environment.
  • Launching new environment named Default-environment.
  • The above sample application automatically deploy into Default-environment.

Then we will get a window as shown below
Launching first application

In Left side screen, show some menu list.

The configuration provides all setting like Scaling, Instances, Notifications, Software Configuration, Updates and Deployments and Network tier etc. We can change all these configuration according to your needs.
The Log provides all information about instance as log file. We can down last 100 line log information.
The Monitoring provides the details about CPU utilization network usage etc. We create Alarm according to that usage.
The Alarms is cloud watch alarm. If we set any alarm in monitoring page then it will display on this page.
The Events page shows all information and about this environment. We can easily filter these information.
The Tags page shows all meta data like Key-Value pair assigned to environment.
      Eg : Key is Name .Then Value is Default-Environment.

The above Image have marked with label ONE(1).Just click on that link new sample page will show on new tab. The new sample page as follows:
Success page

Step 3: If you need to deploy your own application.
For this purpose, you need click on Upload and Deploy button as shown below:
Deploy Application

It generate a popup window:
Versioning

First click on Application Version link and check your label name is unique or not. Then upload your entire ZIP file which contains your application as normal file upload then click Deploy button.
That’s it.
It may take several minutes. Then URL is ready for use. Just click on that URL. ####If any AWS Elastic Beanstalk applications already exist in the region in which you want to create and deploy an application Step 1: Click Create New Environment. Then a generated screen as follows:
Environment type
In the above image,

  • The first drop down box showing Environment tier. The first value is web server, which is used for handling web request. The second value worker tier, which is used for background job.
  • The second drop down is used for select your platform.
  • The third drop down specify single or load balancing instance.

    After you select these entire values click next button
    Step 2:Choose Application version Application versioning
    In this page specify your application file and S3 URL.You have option to choose existing application or new application file upload. Then click Next button.
    Step 3: In this page specify environment name, URL and any descriptions.
    Here you have an option for availability of URL. Then click Next button
    .
    Environment Info

    Step 4: Additional resources If you need additional resources like relational database or Virtual private cloud etc. then choose that parameter also.
    Step 5: Configuration details Configuring
    Specify instance type, notification email address etc. Then click Next button.
    Step 6: Here you can add up to 7 unique key values.
    Step 7: It is a review page before launching the application and you application is now one click away.
    Step 8: Click Launch
    Your application is now ready to use.

####Command Line interface(CLI) Amazon provides another method to deploy your application. You can choose this method if you are uncomforted with management console .But this method should have its own advantage. If you need to change single file from your application instead of entire zip folder then CLI method is more suitable than management console.

Let's begin journey through CLI
Before starting CLI method we should need some configuration. Here explained configuration for Windows operating system.
Step 1: First download and install GIT.
Step 2: After successful installation of GIT, we need some more configuration based on AWS-CLI tool.
Step 3: Download and unzip Command Line Tool. Here the link for download.
[http://aws.amazon.com/code/6752709412171743]
Step 4: You should setup environment variable in windows. First locate your CLI Tool folder after downloaded. Then setup you environment variable. Configuring
Step 5: Take your command prompt .Then redirect to your application page by using DOS command
cd c:\your application folder path
Step 6: Initialize GIT by git init command.
Step 7: Add files and folder to Git by git add filename. If you need to add entire folder then use git add . [Note: ‘.’ Is important].
Step 8: Commit the current files or folders .use the command git commit -m "comments". The comment specify any comment related to commit.
Step 9: For initializing Elastic Beanstalk you can type command eb init.
Step 10: Then proceed with following information like

  • AWS access key ID.
  • AWS secret access key.
  • Service Region.
  • Elastic Beanstalk Application name.
  • Elastic Beanstalk environment name.
  • Environment Tier (worker or Webserver).
  • Available solution stack.
  • Available environment type.
  • If you need relational database instance.

Then it will check with some permission. You can proceed these step without attaching instance profile. An application is created and it should be displayed on your dashboard.

Configuring

Step 11: Now we can start Elastic Beanstalk by eb start command.
Step 12: Then Deploy latest GIT commit on your environment.
Step 13: Push all files git aws.push command.
That’s it! Your application is ready for use. The second method for deploy an application is over.

####Integrated tool with Visual studio and Eclipse Visual studio provides integrated tool for deploy an application through Elastic Beanstalk. Amazon provides excellent guideline through their document. For more details visit here.

The Eclipse also provide integrated tool for deploy your application. For more detail study visit here.

##How to Monitoring In your web application, It is very important to know your application is currently running stage and responding to every request. Manual monitoring all these things is very complex task and it should be need more infrastructures. For replacing these entire barrier AWS introduce more useful technology along with Elastic Beanstalk called Health Monitoring.
After the health check of particular web application respond as one of four colors. The four colors are:

  • Green
    Your application respond to application health check URL within last minute.
  • Yellow
    Your application not respond to application health check URL within last five minutes
  • Gray
    Your application's health status is unknown because status is reported when the application is not in the ready state.
  • Red
    Your application hasn't responded to the application health check URL for more than five minutes.
    Health check URL
    To check the health of your application, Elastic load balancing send request every one or two minutes to health check URL. If you specify you application path like /app/mydemo.php then health check URL is http:80//app/mydemo.php.Elastic load balancing use TCP:80 for non-legacy and HTTP:80 for legacy(legacy applications and data are those that have been inherited from languages, platforms, and techniques earlier than current technology)configurations.

##Auto scaling Auto scaling is a mechanism in which increase or decrease the number of EC2 instance within your application's architecture. scaling offers maximum benefit of AWS cloud. Here some significant features, these are:

####How Auto Scaling Works Configuring

  1. We have auto scaling group with capacity two instances.
  2. When a scale out event occurred. That means some additional task occurred.
  3. Auto scaling launches and configure new instance.
  4. The new instance is added to instance group.
  5. When scale out event occurred. That means additional task removed.
  6. Instance will remove from instance group.
  7. The removed instance will terminate.

####Auto Scaling Instance States The Auto Scaling instance should have four state:

  1. Pending State - Installing software to pending instances.
  2. InService - Updating and modifying instances in auto scaling group.
  3. Terminating - Analyzing an instance before terminating.
  4. Terminated - Instance terminated.

##Conclusion In this article, we showed you how easy it is to deploy a application on Elastic Beanstalk. In the process, we introduced basic concept and detail study to deploy application in elastic Beanstalk.