Skip to content

Latest commit

 

History

History
234 lines (161 loc) · 13.8 KB

aws-advent-day-12-elastic-beanstalk.md

File metadata and controls

234 lines (161 loc) · 13.8 KB

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.

What does Elastic Beanstalk offer me? FAQ Getting Started Walkthrough What Is AWS Elastic Beanstalk and Why Do I Need It?

Pricing

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 total charges for the activity we'll do during this blog post will be minimal (typically less than a dollar). It is possible to do some testing of EB in Free tier by following this guide.

Further Reading on Pricing

Key Concepts

The key concepts when trying to understand and use Elastic Beanstalk are

  • Application
  • Environment
  • Version
  • 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.

Application

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.

Version

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.

Environment

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.

Environment Configuration

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

Configuration Template

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.

Further Reading

Workflow

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.

Supported Languages

Elastic Beanstalk currently supports the following languages:

Getting Started

To get started with Elastic Beanstalk, we'll be using the AWS console.

  1. Login to the console and choose the Elastic Beanstalk service.
  2. Select your application platform, we'll use Python for this example, then click Start
  3. 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."
  1. 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.

Further Reading

Deploying an application

There are two ways to deploy applications to your EB environments

  1. Manually through the AWS console
  2. Using the AWS DevTools, in conjunction with Git or an IDE like Visual Studio or Eclipse.

Manual Deploy

Let's do a manual update of the application through the console

  1. Since we're using Python as our example framework, I am using the python sample from the Getting Started walk through
  2. Login to the EB console
  3. Click on the Versions tab
  4. Click Upload New Version
  5. Enter Second Version for the Version Label
  6. Choose the python-secondsample.zip and Upload it
  7. Under Deployment choose Upload, leave the environment set to Default-Environment
  8. Click Upload New Version
  9. You should now see Second Version available on the Versions tab

Now we can deploy the new version of the application to our environment

  1. Check the box next to Second Version
  2. Click the Deploy button
  3. Set Deploy to: to Default-Environment
  4. Click Deploy Version
  5. Below your list of Versions it will now display the Default-Environment.
  6. You can click on the Events tab to watch the progress of this deploy action.
  7. Wait for the Environment update completed successfully. event to be logged.

Once the deployment is finished, you can check it by

  1. Clicking on the Overview tab
  2. Expanding your application environment, e.g. Default-Environment
  3. Reviewing the Running Version field.
  4. It should now say Second Version

CLI Deploy

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.

  1. Get the ELB command line tools downloaded and installed
  2. Unzip the python sample into a directory and initialize that directory as a Git repository with git init
  3. Adding everything in the directory to the repo with git add * and commit it with git commit -a -m "all the things"
  4. 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.
  5. Follow the Git setup steps to setup the DevTools with your AWS credentials, application, and environment names.
  6. Edit application.py in your Git repo and add a comment like # I was here
  7. Commit this change with git commit -a -m "I was here"
  8. 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
  9. 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 git aws.push

Further Reading

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

  1. Login to the AWS console
  2. Locate your environment and click on Actions
  3. Make your desired changes to the settings
  4. 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.

Further reading on Environment Customization

Customizing Application Containers

At this time, the following container types support customization

  • Tomcat 6 and 7 (non-legacy container types)
  • Python
  • 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

  • Packages
  • Sources
  • Files
  • Users
  • Groups
  • Commands
  • Container_commands
  • Services
  • Option_settings

Further Readingon Application Container Customization

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: