In this session, we introduce you to a solution for easily running a Docker-powered microservices architecture on AWS using Elastic Beanstalk. We will also cover the fundamentals of Elastic Beanstalk and how it benefits developers looking for a quick and scalable way to get their applications running on AWS with no infrastructure work required.
Building a microservices architecture using Docker can require a lot of work, from launching and operating the underlying infrastructure to installing and maintaining cluster management software. With AWS Elastic Beanstalk’s multicontainer support feature, many of these tasks are simplified and abstracted away so you can focus on your application code. AWS Elastic Beanstalk 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."
Learning Objectives:
• Learn the basics of AWS Elastic Beanstalk
• Understand how to use Elastic Beanstalk to run containerized applications
• Learn how to use Elastic Beanstalk to start architecting microservices-based applications
2. Agenda
Elastic Beanstalk vs DIY
How to use Elastic Beanstalk
Multi-Container Docker with AWS Elastic Beanstalk
Recently added features
3. Developer Challenges
Complexity of deploying code, provisioning
and managing infrastructure
Expertise and time needed to manage and
configure servers, databases, load
balancers, firewalls, and networks
How to automate application scaling
4. What is Elastic Beanstalk?
AWS Elastic Beanstalk is an easy-to-use service for
deploying and scaling web applications and services.
5. AWS Elastic Beanstalk vs. Do It Yourself
Your code
HTTP Server
Application Server
Language Interpreter
Operating System
Host
Elastic Beanstalk configures each
EC2 instance in your
environment with the components
necessary to run applications for
the selected platform.
Focus on building your
application
Provided by you
Provided and managed by AWS Elastic Beanstalk (EB)
On-instance configuration
6. AWS Elastic Beanstalk vs. Do It Yourself
Preconfigured Infrastructure
Single Instance (Dev, Low Cost)
Load Balanced, Auto Scaling (Production)
Web & Worker tiers
Elastic Beanstalk provisions necessary
infrastructure resources such as the load
balancer, auto scaling group, security
groups, database (optional), etc.
Provides a unique domain name for your
application
(e.g.:
youapp.regionx.elasticbeanstalk.com)
Infrastructure stack
7. Common Use Cases
Websites
API backends
Mobile backends
Asynchronous workers
9. Elastic Beanstalk Benefits
Fast & simple
to begin
Developer
productivity
Impossible
to outgrow
Complete
resource control
No additional charge to use.
You only pay for underlying AWS resources (i.e.: EC2 instances, S3, etc.)
12. Building applications with Elastic Beanstalk
Application: api
Environment
prod-api V1
Environment
dev-api V1.1
Environment
browserClient V2
Environment
browserClient V2.1
Environment
dev-api V1.2
Environment
browserClient V3
Application: browser
13. How to deploy applications
1. Via AWS Management Console
2. Via AWS Toolkit for Eclipse and Visual
Studio IDE
3. Via AWS SDK’s and CLI
4. Via EB command line interface
$ eb deploy
14. Deploy Sample Application (EB CLI)
Initial application deployment workflow
$ git clone
https://github.com/awslabs/eb-
node-express-sample.git
Download sample application02
$ eb init
Create your Elastic Beanstalk app03
Follow the prompts to configure the
environment
04
05 Create the resources and launch the
application
$ eb create
$ pip install --upgrade awsebcli
Install the AWS Elastic Beanstalk
command line interface (EB CLI)
01
15. Update Sample Application (EB CLI)
Update application workflow
Update your code01
$ git add .
$ git commit –m “v2.0”
$ eb deploy
Add & commit code to repository02
Open application once deployment
completes.
03
$ eb open
17. Benefits of using Multi-Container Docker with
Elastic Beanstalk
Automation of capacity provisioning, load balancing,
scaling, and application health monitoring
One stop management of your application in an
environment that supports range of services that are
integrated with Elastic Beanstalk, including but not
limited to VPC, RDS, and IAM.
18. I’ve built my containers, how do I…?
Store my container images?
Configure containers for Beanstalk?
Test my config?
Deploy to Beanstalk?
Update my application?
19. Store your container images: Amazon ECR
Beanstalk can interact with any Docker Repository
Options include Dockerhub, Amazon ECR, and private
repos
Amazon ECR allows access control via IAM for fine-
grained permissions
Elastic Beanstalk can automatically authenticate with
ECR
21. Dockerrun.aws.json: Introduction
Specifies the version number as the value "2" for
multicontainer Docker environments
AWSEBDockerrunVersion01
An array of container definitions
ContainerDefinitions03
Mount points in the container instance that a container can use
Volumes02
"volumes": [
{
"name": "volumename",
"host": {
"sourcePath": "/path/on/host/instance"
}
}
],
Format:
23. Test your Beanstalk application locally
Use EB “eb local run” command to run and test
dockerrun.aws.json application locally
24. Choose the right Beanstalk container platform
Single Container Docker
Multi-Container Docker
25. Multi Container: Architecture
Each environment has its own ECS Cluster
Supports a single ECS Task definition per environment
The ECS Task is defined in the Dockerrun.aws.json file
Uses a flood scheduling mechanism
Provides out of the box auto scaling for ECS Tasks
Elastic Beanstalk Environment
Auto Scaling Group / ECS Cluster
Instance 1 Instance 2
app1.elasticbeanstalk.com
Elastic Load
Balancing
Container 2Container 1
Container 3
Container 2Container 1
Container 3
26. Multi Container with Elastic Beanstalk
Nginx Proxy Example
Code at: https://github.com/awslabs/eb-docker-nginx-proxy
28. Update your application: Deployment Policies
All at once: Deploy new version to all instances
simultaneously
Rolling: Deploy new version in batches
Rolling with additional batch: Deploy in batches, +1 extra
batch
Immutable: Deploy to fresh group of instances
42. Update your application: Blue/Green
Pros:
Fast rollback because the previous environment is still running
Cons:
Slower deployment (5 minutes) due to new environment spin-up
Potential of DNS caching by mobile clients after CNAME swap
43. Step 0: Blue/Green
Auto Scaling Group
Elastic Beanstalk Environment
v1 v1
myapp.elasticbeanstalk.com
v1v1
44. Step 1: Blue/Green
Auto Scaling Group
Elastic Beanstalk Environment
v1 v1
myapp.elasticbeanstalk.com
v1v1
Auto Scaling Group
v2
45. Step 2: Blue/Green
Auto Scaling Group
Elastic Beanstalk Environment
v1 v1
myapp.elasticbeanstalk.com
v1v1
Auto Scaling Group
v2
46. Step 3: Blue/Green
Auto Scaling Group
Elastic Beanstalk Environment
v1 v1
myapp.elasticbeanstalk.com
v1v1
Auto Scaling Group
v2 v2 v2v2
47. Step 4: Blue/Green
Auto Scaling Group
Elastic Beanstalk Environment
v1 v1
myapp.elasticbeanstalk.com
v1v1
Auto Scaling Group
v2 v2 v2v2
48. Step 5: Blue/Green
Auto Scaling Group
Elastic Beanstalk Environment
v1 v1
myapp.elasticbeanstalk.com
v1v1
Auto Scaling Group
v2 v2 v2v2
49. Step 6: Blue/Green
Auto Scaling Group
Elastic Beanstalk Environment
v2 v2
myapp.elasticbeanstalk.com
v2v2
52. Recently added features
• Support for Application Load Balancer - Learn more
• Support for ASP.NET Core and Multi-App .NET deployment -
Learn more
• Support for EC2 Container Registry - Learn more
• Managed Updates - Learn more
53. Questions?
How to get in touch with the EB team?
Forum:
https://forums.aws.amazon.com/forum.jspa?forumID=86
Twitter
@aws_eb
Editor's Notes
Hello everyone, I’m brandon chavis, and I’m a solutions architect based in seattle washington
Today we’re covering aws elastic beanstalk, which is a service for deploying and scaling web applications.
The agenda for today is pretty straightforward, I suspect as usual we have a wide range of experience on the webinar today
If you’re new to AWS and elastic beanstalk, never fear, for we will cover a little bit of the basics of elastic beanstalk
What it is, why you’d want to use it
And we’ll progress to how you can get started using it
And then we’ll focus on deploying docker applications to the multi-container docker environment type, and we’ll demo how this works with amazon ECR at the end
Finally, we’ll chat a bit about some new features to elastic beanstalk. Let’s get started.
Like everything in AWS, we built elastic beanstalk to solve a customer problem. It can be hard to be a developer right now- there’s so much to know, and you might be expected to be awesome at everything
You might be an excellent java developer, but you don’t know anything about elastic load balancers. You might be a really strong ops engineer and you just need to get some code deployed, and you can’t spend all your time configuring the full architecture stack. You have some code, and you want it running in the cloud.
We understand these challenges better than anyone- I find it difficult just to stay up to date with AWS new releases and features.
AWS Elastic Beanstalk is built to offload much of this heavy lifting from you and get your code deployed into a best-practices aws stack with minimal configuration.
We like to say it’s impossible to outgrow, and that’s because it’s built with growth in mind. It’s built around the concept of scaling with your needs.
We want to enable you to focus on your application by providing you a choice of pre-configured environments. EB will spin up instances that are pre-configured with software, config files, app or web server frameworks- basically everything you need to run your code.
In my opinion this is wonderful not only because it minimizes the configuration you need to do yourself, but it also enforces a baseline common config on all the instances in your environment, minimizing risk of dependency drift for your software.
Not only is your EC2 instance configured for you, but there’s an entire pre-configured architecture stack spun up for you. You can, of course, choose to run a single instance deployment to save costs in developent environments, but you can automatically spin up an auto-scaled and load balanced environment right off the bat.
You can also choose between a “web tier” environent, which is your more typical 3 tier web app, or a worker tier, which is an environment that focuses on handling asynchronous work, like from an SQS queue
The full stack is included: a custom R53 dns name for each application, an elastic load balancer, ec2 instances in an autoscaling group, and optionally a backend persistence layer like an RDS database. You also get a lot of the glue- an S3 bucket for your source code and logs, security groups, and cloudwatch alarms.
These resources are your AWS resources, the same resources that you are used to, and they run in your account and you maintain full control of them.
One note about RDS databases with your stack
So common use cases that are pretty straightforward
EB works very very well for websites and APIs
Beanstalk Is suitable for a very wide range of use cases as well- from a single developer just looking to get his code up to the cloud, to a global fortune 500 company. Zillow, for example, runs both Front end APIs and image conversion applications in elastic beanstalk environments.
Because their workloads are unpredictable, they like the ability of beanstalk to scale up in response to these load fluctuations.
So, in summary: beanstalk is a convenient management layer for the AWS services that you know today, and it’s totally free. You pay for the underlying resources.
It’s is the fastest and simplest way to deploy your application on AWS. You simply upload your application, and Elastic Beanstalk automatically handles the deployment details. Within minutes, your application will be ready to use without any infrastructure or resource configuration work on your part.
Elastic Beanstalk provisions and operates the infrastructure and manages the application stack for you, so you don't have to spend the time or develop the expertise. Instead, you can focus on writing code rather than spending time managing and configuring servers, databases, load balancers, firewalls, and networks.
Elastic Beanstalk automatically scales your application up and down based on your applications specific need using easily adjustable Auto Scaling settings. For example, you can use CPU utilization metrics to trigger Auto Scaling actions. With Elastic Beanstalk, your application can handle peaks in workload or traffic while minimizing your costs.
Additionally, Elastic Beanstalk lets you "open the hood" and retain full control over the AWS resources powering your application. If you decide you want to take over some (or all) of the elements of your infrastructure, you can do so seamlessly by using Elastic Beanstalk's management capabilities.
So, to get started, you need to make a few decisions, or answer a few questions when spinning up an environment.
Choose an AWS region. Pick the one closest to your customers, or pick one of our four carbon neutral datacenters, it’s all good
Pick your stack type. This is not really a decision for you, just pick the platform that corresponds to your app. Java tomcat, Java Jetty, Go, PHP, .net, Nodejs, Ruby with passenger or puma, python…
Is this a development environment or a production one? Choose the single instance type if you’re being frugal, otherwise go hog wild and get that autoscaled and ELB environment.
Last, do you need a database? One thing to note about RDS databases with Beanstalk is the database, if launched through beanstalk, is tied to the life of your environment. Typically the lifecycle of your data exceeds that of your application version, so keep that in mind.
In Elastic Beanstalk an application serves as a container for the environments that run your web app, and versions of your web app's source code, saved configurations, logs and other artifacts that you create while using Elastic Beanstalk.
Applications are the top level contstruct in beanstalk, under which you can have multiple and fully independent environments running in parallel. They can even use different application stacks.
You have read and write access to the repositories you create in your default registry, i.e. <aws_account_id>.dkr.ecr.us-east-1.amazonaws.com
Repository names can support namespaces, e.g. team-a/web-app.
Repositories can be controlled with both IAM user access policies and repository policies
AWSEBDockerrunVersion: Specifies the version number as the value "2" for multicontainer Docker environments.
Volumes - Creates mount points in the container instance that a container can use
containerDefinitions: The container definition and volumes sections of Dockerrun.aws.json use the same formatting as the corresponding sections of an Amazon ECS task definition file.
parameters that are commonly used-
Name - The name of the container.
Image -The name of a Docker image in an online Docker repository from which you're building a Docker container
Environment - An array of environment variables to pass to the container, such as name, value.
Essential - True if the task should stop if the container fails. Nonessential containers can finish or crash without affecting the rest of the containers on the instance
Memory - Amount of memory on the container instance to reserve for the container
mountPoints - Volumes from the container instance to mount and the location on the container file system at which to mount them
portMappings - Maps network ports on the container to ports on the host.
Links - List of containers to link to. Linked containers can discover each other and communicate securely.
volumesFrom - Mount all of the volumes from a different container.
A Dockerrun.aws.json file is an Elastic Beanstalk–specific JSON file that describes how to deploy a set of Docker containers as an Elastic Beanstalk application.
A Dockerrun.aws.json file can be used on its own or zipped up with additional source code in a single archive
The Dockerrun.aws.json file includes three sections:
AWSEBDockerrunVersion
Specifies the version number as the value "2" for multicontainer Docker environments.
volumes
Creates mount points in the container instance that a container can use. Configure volumes for folders in your source bundle (deployed to /var/app/current on the container instance) for a container's application to read.
containerDefinitions
The container definition and volumes sections of Dockerrun.aws.json use the same formatting as the corresponding sections of an Amazon ECS task definition file
Name: The name of the container.
Image: The name of a Docker image in an online Docker repository from which you're building a Docker container.
Memory: Amount of memory on the container instance to reserve for the container.
mountPoints: Defines the mountlocations
portMappings: Maps network ports on the container to ports on the host.
Links:List of containers to link to. Linked containers can discover each other and communicate securely.
authentication
(optional) The location in Amazon S3 of a .dockercfg file that contains authentication data for a private repository
Multi-container: Nginx:
This example configuration defines two containers, a PHP web site with an nginx proxy in front of it. These two containers will run side by side in Docker containers on each instance in your Elastic Beanstalk environment, accessing shared content (the content of the website) from volumes on the host instance, which are also defined in this file. The containers thmeselves are created from images hosted in official repositories on Docker Hub
All at once – Deploy the new version to all instances simultaneously. All instances in your environment are out of service for a short time while the deployment occurs.
Rolling – Deploy the new version in batches. Each batch is taken out of service during the deployment phase, reducing your environment's capacity by the number of instances in a batch.
Rolling with additional batch – Deploy the new version in batches, but first launch a new batch of instances to ensure full capacity during the deployment process.
Immutable – Deploy the new version to a fresh group of instances by performing an immutable update.
Batch type – Whether you want to allocate a percentage of the total number of EC2 instances in the Auto Scaling group or a fixed number to a batch of instances.
Batch size – The number or percentage of instances to deploy in each batch, up to 100 percent or the maximum instance count in your environment's Auto Scaling configuration.