Amazon Elastic Beanstalk
Elastic Beanstalk (EB) is a service which helps you easily manage and deploy your application code into an automated application environment. It handles provisioning AWS resources like EC2 instances, ELB instances, and RDS databases, and let’s you focus on writing your code and deploying with a
git push style deployment when you’re ready to deploy to development, staging, or production environments.
AWS Elastic Beanstalk is free, but the AWS resources that AWS Elastic Beanstalk provides are live (and not running in a sandbox). You will incur the standard usage fees for any resources your environment uses, until you terminate them.
The key concepts when trying to understand and use Elastic Beanstalk are
- Environment Configuration
- Configuration Template
The primary AWS services that Elastic Beanstalk can/will use are
- Amazon Elastic Compute Cloud (Amazon EC2)
- Amazon Relational Database Service (Amazon RDS)
- Amazon Simple Storage Service (Amazon S3)
- Amazon Simple Notification Service (Amazon SNS)
- Amazon CloudWatch
- Elastic Load Balancing
- Auto Scaling
It’s important to understand what each of the main components in Elastic Beanstalk, so let’s explore them in a little more depth.
An AWS Elastic Beanstalk application is a logical collection of AWS Elastic Beanstalk components, including environments, versions, and environment configurations. In AWS Elastic Beanstalk an application is conceptually similar to a folder.
In AWS Elastic Beanstalk, a version refers to a specific, labeled iteration of deployable code. A version points to an Amazon Simple Storage Service (Amazon S3) object that contains the deployable code (e.g., a Java WAR file). A version is part of an application. Applications can have many versions.
An environment is a version that is deployed onto AWS resources. Each environment runs only a single version, however you can run the same version or different versions in many environments at the same time. When you create an environment, AWS Elastic Beanstalk provisions the resources needed to run the application version you specified. For more information about the environment and the resources that are created, see Architectural Overview.
An environment configuration identifies a collection of parameters and settings that define how an environment and its associated resources behave. When you update an environment’s configuration settings, AWS Elastic Beanstalk automatically applies the changes to existing resources or deletes and deploys new resources (depending on the type of change).
A configuration template is a starting point for creating unique environment configurations. Configuration templates can be created or modified only by using the AWS Elastic Beanstalk command line utilities or APIs.
The typical workflow for using Elastic Beanstalk is that you’ll create one or more environments for a given application. Commonly development, staging, and production environments are created.
As you’re ready to deploy new versions of your application to a given environment, you’ll upload a new version and deploy it to that environment via the AWS console, the CLI tools, an IDE, or the an EB API library.
- Deploying PHP using the CLI and Git
- Deploy .NET Using AWS Toolkit for Visual Studio
- Deploy Java Using AWS Toolkit for Eclipse
Elastic Beanstalk currently supports the following languages:
To get started with Elastic Beanstalk, we’ll be using the AWS console.
- Login to the console and choose the Elastic Beanstalk service.
- Select your application platform, we’ll use Python for this example, then click Start
- AWS will begin provisioning you a new application environment. This can take a few minutes since it involves provisioning at least one new EC2 instance. EB is performing a number of steps while you wait, including
- Creating an AWS Elastic Beanstalk application named “My First Elastic Beanstalk Application.”
- Creating a new application version labeled “Initial Version” that refers to a default sample application file.
- Launching an environment named “Default-Environment” that provisions the AWS resources to host the application.
- Deploying the “Initial Version” application into the newly created “Default-Environment.”
- Once the provisioning is finished you are able to view the default application by expanding the Environment Details and clicking on the URL
At this point we have a deployed EB managed application environment.
Deploying an application
There are two ways to deploy applications to your EB environments
- Manually through the AWS console
- Using the AWS DevTools, in conjunction with Git or an IDE like Visual Studio or Eclipse.
Let’s do a manual update of the application through the console
- Since we’re using Python as our example framework, I am using the python sample from the Getting Started walk through
- Login to the EB console
- Click on the Versions tab
- Click Upload New Version
- Enter Second Version for the Version Label
- Choose the python-secondsample.zip and Upload it
- Under Deployment choose Upload, leave the environment set to Default-Environment
- Click Upload New Version
- You should now see Second Version available on the Versions tab
Now we can deploy the new version of the application to our environment
- Check the box next to Second Version
- Click the Deploy button
- Set Deploy to: to Default-Environment
- Click Deploy Version
- Below your list of Versions it will now display the Default-Environment.
- You can click on the Events tab to watch the progress of this deploy action.
- Wait for the Environment update completed successfully. event to be logged.
Once the deployment is finished, you can check it by
- Clicking on the Overview tab
- Expanding your application environment, e.g. Default-Environment
- Reviewing the Running Version field.
- It should now say Second Version
Being able to deploy from the command line and with revision control is ideal. So Amazon has written a set of tools, the AWS DevTools, that integrate with Git to help get this workflow up and running.
Let’s walk through doing a CLI deploy. I am going to assume you already have Git installed.
- Get the ELB command line tools downloaded and installed
- Unzip the python sample into a directory and initialize that directory as a Git repository with
- Adding everything in the directory to the repo with
git add *and commit it with
git commit -a -m "all the things"
- From your Git repository directory, run AWSDevTools-RepositorySetup.sh. You can find AWSDevTools-RepositorySetup.sh in the AWS DevTools/Linux directory. You need to run this script for each Git repository.
- Follow the Git setup steps to setup the DevTools with your AWS credentials, application, and environment names.
- Edit application.py in your Git repo and add a comment like
# I was here
- Commit this change with
git commit -a -m "I was here"
- Push your change to your EB application environment with
git aws.push, you can see what this should look like in the example on deploying a PHP app with Git and DevTools
- If you’re Push succeeds, you should see the Running Version of your application show the Git SHA1 of your commit.
You can now continue to work and deploy by committing to Git and using
Application Environment Configurations
Once you’re familiar and comfortable with deploying applications, you’ll likely want to customize your application environments. Since EB uses EC2 instances running Linux or Windows, you have a certain amount of flexibility in what customizations you can make to the environment.
Customizing Instance Options
You’re able to tweak many options regarding your instances, ELB, Auto-Scaling, and Database options, including
- Instance type
- EC2 security group
- Key pairs
- Port and HTTPS options for ELB
- Auto-Scaling instance settings and AZ preference
- Setting up your environment to use RDS resources.
To customize these things, you
- Login to the AWS console
- Locate your environment and click on Actions
- Make your desired changes to the settings
- Click Apply Changes
As mentioned, some changes can be done on the fly, like ELB changes, while others, like changing the instance size or migrating to RDS, require a longer period of time and some application downtime.
Customizing Application Containers
At this time, the following container types support customization
- Tomcat 6 and 7 (non-legacy container types)
- Ruby 1.8.7 and 1.9.3
- Currently, AWS Elastic Beanstalk does not support configuration files for PHP, .NET, and legacy Tomcat 6 and 7 containers.
You’re able to customize a number of things, including
Where to go from here
Now that you’re used Elastic Beanstalk, seen how to deploy code, learned how to customized your instances, you may be considering running your own application with Elastic Beanstalk.
Some of the things you’ll want to look into further if you want to deploy your application to EB are: