This document is divided into 2 main parts:
- Concepts and Diagrams: lists and comments important sections to get used with AWS EB concepts.
- Hands-on: let's make something useful. :-P
http://docs.aws.amazon.com/elasticbeanstalk/latest/dg/images/clearbox-flow-00.gif
MUST READ
EB APPLICATION
+---------------------------------------------------------------+
| |
| +----------------------------+ |
| | AWS RESOURCES (deployed) | |
| +-------------------+ |----------------------------| |
| | VERSION 1 | | | |
| | | | +------------------+ | |
| +-------------------+ | | env A | | |
| | VERSION 2 | | | (VERSION 2) | | |
| | | | | (ENV CONFIG x) | | |
| +-------------------+ | +------------------+ | |
| | VERSION n | | | env B | | |
| | | | | (VERSION 2) | | |
| +-------------------+ | | (ENV CONFIG y) | | |
| | ENV CONFIG x | | +------------------+ | |
| +-------------------+ | | env B | | |
| | ENV CONFIG y | | | (VERSION n) | | |
| +-------------------+ | | (ENV CONFIG x) | | |
| | +------------------+ | |
| | | |
| +----------------------------+ |
| |
+---------------------------------------------------------------+
- Application: has versions, environments and environment configs.
- Application version: Each application version is unique and you might have different versions deployed to an environment if you have a need to test changes you’ve made between one version of your application and another.
- Environment: An environment is a version that is deployed onto AWS resources.
- You can run the same version or different versions in many environments at the same time.
- The environment is the heart of the application.
The diagram below shows the components of an environment:
- Each environment has a elastic load balancer, a security group, an auto scaling group and one or more EC2 instances inside it.
- There's a HOST MANAGER (HM) running inside each EC2 instance allocated for an environment.
- The HM deploys the app.
- Every environment has a CNAME (URL) that points to a load balancer. The environment has a URL such as MyApp.elasticbeanstalk.com. This URL is aliased in Amazon Route 53 to an Elastic Load Balancing URL—something like abcdef-123456.us-east-1.elb.amazonaws.com—by using a CNAME record. Your domain name that you registered with your DNS provider will forward requests to the CNAME.
For more information about designing scalable application architectures for AWS, read AWS Cloud Best Practices (PDF).
(end of PART I)
### Getting Started Using AWS Elastic Beanstalk (the web console tool)
http://docs.aws.amazon.com/elasticbeanstalk/latest/dg/GettingStarted.html
Creates a default application and makes deploy of 2 versions of it using AWS EB console (web).
You can practice changing versions on the fly in a live server with no downtime. A nice playground. :-)
Just useful links to getting started with Eb, operations and Getting Set Up.
http://docs.aws.amazon.com/elasticbeanstalk/latest/dg/command-reference-get-started.html
Or, "deploying an empty application"
I highly recommend you to create a brand new virtualenv to play with eb in this study phase. And, working with virtualenv, enjoy virtualenvwrapper, too. We'll use both of them here.
To start, follow these steps:
-
Download
eb
from AWS Elastic Beanstalk Command Line Tool Download page. -
Unzip it to your
~/bin
directory.The unzip process will create the directory AWS-ElasticBeanstalk-CLI-2.6.0 (or something similar, if you downloaded another version) inside your
~/bin
. -
mkproject aws_eb
This will create your virtualenv project for this exercise.
-
Edit your
$VIRTUAL_ENV/bin/postactivate
file and append this line to it:export PATH=~/bin/AWS-ElasticBeanstalk-CLI-2.6.0/eb/linux/python2.7:$PATH
Important: I'm considering you're using Linux and Python 2.7. If you're using Mac OS, change the "linux" part to "mac". If you're using Python 3, change the "python2.7" part to "python3".
-
deactivate
-
workon aws_eb
Deactivate and activate it again to get the new path.
-
git init .
-
eb init
Answer questions following the tutorial to initialize your
eb
settings (local and remote).Note: I didn't choose to create a RDS instance.
-
eb start
Yes, you're right, we are deploying an empty application with an empty git repo!
In this case, AWS configures the same "Sample Application" we used in the previous Getting Started Using AWS Elastic Beanstalk (the web console tool) section.
Note: this step can take some time and you'll have to wait.
If everything went OK, you see the last INFO message showing something simmilar to this:
2014-03-18 22:28:20 INFO Successfully launched environment: HelloWorld-env
Application is available at "HelloWorld-env-tjehzq4giw.elasticbeanstalk.com".
Now you can copy & paste the URL shown. That is your application URL and you have a running Python application, the same way we had in the console example.
If you go into your AWS EB console, you'll see your application and your environment there.
Congratulations, mission accomplished. \o/
Note to self: an environment is what AWS calls "a deployed application".
eb init
: initializes your configs for an application.eb start
: deploys an application (creates the environment and associated resources).eb stop
: deletes an environment (delete load balancer, security group and auto scaling group and stop EC2 instances allocated)eb delete
: deletes the application.
http://docs.aws.amazon.com/elasticbeanstalk/latest/dg/command-reference-branch-environment.html
Or "really deploying my code".
-
Create a branch of your repo, let's say "testing_branch".
-
Insert some code to this branch and commit.
When you deploy a new branch, you'll be deploying a new application version.
Tip 1: If you're a kind of lost, like I was when playing with this step, you'll like to get the "second application version" you downloaded when practicing the AWS EB web console, unzip it (it's just one python file), change the H1 tag with your name, for instance, and commit it.
Tip 2: The commit message will become the new version description in AWS EB web console.
-
Map your current branch to a specific environment.
$ eb branch
In this step you'll be asked some questions. Answer them.
Tip: probably you'll have to name an environment. Environment names must follow these rules: they "must contain only letters, digits, and the dash character and may not start or end with a dash". So, create something like
testing-env
.If you just created a new environment, you'll need to
eb start
it before going on. Remind to copy it's url shown in last line of INFO log. -
Deploy your branch.
$ git aws.push
Done. :-)
Now, if you go to AWS EB web console, you'll see 2 environments. Also, you'll see 2 versions in application versions page. Both of them deployed. \o/
Important: It may occur when you go to AWS EB web console, your see the new environment in gray. It's because your new application version is still being deployed. Wait a little and it'll be green.
You can, optionally, use git aws.push --environment <some_other_env_name>
. In this case you'll be deploying current branch to another environment, instead of that environment configured in previous eb branch
.
Now we know how to deploy different versions through command line. So, it's show time. :-)
Let's deploy a new app version to other environment.
-
git checkout master
Enter into
master
branch. -
git checkout testing_branch -- application.py
Copy your
application.py
from branchtesting_branch
tomaster
. -
Edit your
application.py
and change the word "second" to "FIRST". Save it. -
git add application.py
-
git commit -m "A new first version"
-
git aws.push --environment testing-env
You'll see a message in your terminal telling you this version was uploaded and environment update was forced. That's what we expect.
Enter in your AWS EB web console to see the environment being updated (gray color, remember?) and wait until it's green.
-
Go to your testing environment URL. You'll see the page you just pushed.
Now, you can restore your testing environment version, checking out your testing_branch
and issuing a git aws.push
.
http://docs.aws.amazon.com/elasticbeanstalk/latest/dg/create_deploy_Python.html
Just finished – great tutorial, even though I'd leave the virtualenvwrapper out of it for simplicity