Distribua, gerencie e escale suas aplicações com o aws elastic beanstalk

40
Distribua, Gerencie e Escale suas Applicações com o AWS Elastic Beanstalk Ari Dias Neto, AWS Solutions Architect

Transcript of Distribua, gerencie e escale suas aplicações com o aws elastic beanstalk

Distribua, Gerencie e Escale suas

Applicações com o AWS Elastic

Beanstalk

Ari Dias Neto, AWS Solutions Architect

Creating a HA Architecture

Decompose into small,

loosely coupled, stateless

building blocks

Prerequisite

What does this mean in practice?

• Only store transient data on local disk

• Needs to persist beyond a single http request?

– Then store it elsewhere

User uploads

User Sessions

Amazon S3

DynamoDB

Application Data

Amazon RDSElastiCache

Having decomposed into

small, loosely coupled,

stateless building blocks

You can now Scale out with ease

Having done that…

Having decomposed into

small, loosely coupled,

stateless building blocks

We can also Scale back with ease

Having done that…

High Availability

Availability Zone a

Web

serverS3 bucket for

static assets

www.example.com

Amazon Route 53

DNS service

High Availability

S3 bucket for

static assets

www.example.com

Amazon Route 53

DNS service

Availability Zone a Availability Zone b

Web

serverWeb

server

High Availability

S3 bucket for

static assets

www.example.com

Amazon Route 53

DNS service

Availability Zone a Availability Zone b

Elastic Load

Balancing

Web

serverWeb

server

High Availability

Availability Zone a

RDS DB

instance

Availability Zone b

www.example.com

Amazon Route 53

DNS service

Web

serverWeb

serverS3 bucket for

static assets

Elastic Load

Balancing

High Availability

Availability Zone a

RDS DB

instance

Availability Zone b

www.example.com

Amazon Route 53

DNS service

Web

serverWeb

serverS3 bucket for

static assets

Elastic Load

Balancing

RDS DB

standby

High Availability

Availability Zone a Availability Zone b

www.example.com

Amazon Route 53

DNS service

Web

serverWeb

serverS3 bucket for

static assets

Elastic Load

Balancing

RDS DB

instance

ElastiCache

node 1

RDS DB

standby

High Availability

Availability Zone a Availability Zone b

www.example.com

Amazon Route 53

DNS service

Web

serverWeb

serverS3 bucket for

static assets

Elastic Load

Balancing

RDS DB

instance

ElastiCache

node 1

RDS DB

standby

ElastiCache

node 2

High Availability

www.example.com

Amazon Route 53

DNS service

S3 bucket for

static assets

Availability Zone a Availability Zone b

Servers

Elastic Load

Balancing

RDS DB

instance

ElastiCache

node 1

RDS DB

standby

ElastiCache

node 2

Servers

High Availability

www.example.com

Amazon Route 53

DNS service

S3 bucket for

static assets

Availability Zone a Availability Zone b

Servers

Elastic Load

Balancing

RDS DB

instance

ElastiCache

node 1

RDS DB

standby

ElastiCache

node 2

Servers

Production

Environment

High Availability

www.example.com

Amazon Route 53

DNS service

S3 bucket for

static assets

Availability Zone a Availability Zone b

Servers

Elastic Load

Balancing

RDS DB

instance

ElastiCache

node 1

RDS DB

standby

ElastiCache

node 2

Servers

Availability Zone a Availability Zone b

Servers

Elastic Load

Balancing

RDS DB

instance

ElastiCache

node 1

RDS DB

standby

ElastiCache

node 2

Servers

Clone or Dev

Environment

Production

Environment

Take the shortcut

• While this architecture is simple you still need

to deal with: – Configuration details

– Deploying code to multiple instances

– Maintaining multiple environments (Dev, Test, Prod)

– Maintain different versions of the application

• Solution: Use AWS Elastic Beanstalk

AWS Elastic Beanstalk (EB)

• Easily deploy, monitor, and scale three-tier web

applications and services.

• Infrastructure provisioned and managed by EB – but

you maintain complete control.

• Preconfigured application containers that are easily

customizable.

• Support for these platforms:

Basic concepts

Elastic Beanstalk object model

Application

Environments

• Infrastructure resources (such as EC2 instances, ELB load balancers, and Auto Scaling groups)

• Runs a single application version at a time for better scalability

• An application can have many environments (such as staging and production)

Application versions

• Application code

• Stored in Amazon S3

• An application can have many application versions (easy to rollback to previous versions)

Saved configurations

• Configuration that defines how an environment and its resources behave

• Can be used to launch new environments quickly or roll-back configuration

• An application can have many saved configurations

Elastic Beanstalk environment

• Two types:

• Single instance

• Load balancing, auto scaling

• Two tiers (web server and worker)

• Elastic Beanstalk provisions necessary

infrastructure resources such as load

balancers, auto-scaling groups, security

groups, and databases (optional)

• Configures Amazon Route 53 and gives

you a unique domain name

(For example: yourapp.elasticbeanstalk.com)

On-instance configuration

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

• No more worrying about

logging into instances to

install and configure your

application stack

Focus on building your

application

Deploy your background processing app

Alert

Log

Mon

Ap

p

AZ

SQS queueProducers

Application versions and saved configurations

Saved configurationsSave these for easy duplication

for A/B testing or non-disruptive

deployments

Application versionsAll versions are stored durably

in Amazon S3. Code can also

be pushed from a Git repository!

Deployment options

• Via the AWS Management Console

• Via Git / EB CLI

• Via the AWS Toolkit for Eclipse and the

Visual Studio IDE

$ git aws.push

Deployment configuration

Region01

Stack (container) type02

Single instanceLoad balanced with

Auto Scaling03 OR

Database (RDS)04 Optional

Your code

Example: CLI workflow

Initial app deployment:

$ git init . $ git add .

Initialize your Git repository01 Add your code04

$ eb init $ git commit –m “v1.0”

Create your Elastic Beanstalk app02 Commit05

Follow the prompts to configure the

environment03

Create the resources and launch the

application06

$ eb create

Example: CLI workflow

Prerequisites:

• AWS account – your access and secret keys

• EB CLI

• Linux / Unix / Mac: Python 2.7 or 3.0

• Windows PowerShell 2.0

• A credential file containing info from 1

• Git 1.66 or later (optional)

Example: CLI workflow

Update your app:

Update your code01

$ git add .$ git commit –m “v2.0”$ eb deploy

Push the new code 02

Monitor the deployment progress03

$ eb status

Example: Deploy Docker container to EB

• Three ways:

– Dockerfile (image built on instance).

– Dockerrun.aws.json (manifest file that

describes how to run the Docker image).

– Application archive (should include

Dockerfile or Dockerrun.aws.json file).

• Benefits:

– Enables high-fidelity deployments.

– You own the runtime. You can use any

language or framework, even those not

currently supported by Elastic Beanstalk

(such as Go, Scala, and Clojure).

Dockerfile

Dockerrun.aws.json

Example: Deploy Docker container to EB

Using the EB command line tool:

$ git init .

Initialize your Git repository01

$ git add Dockerfile

Add your code04

$ eb init

Create your Elastic Beanstalk app02

$ git commit –am “v1.0”

Commit05

Follow the prompts to configure the

environment and copy Dockerfile03 06

Create the resources and launch the

application

$ eb create

Advanced topics

Customize application containers

Add custom software to your environment using ebextensions:

packages:yum:newrelic-sysmond: []

rpm:newrelic: http://yum.newrelic.com/pub/newrelic/el5/i386/newrelic-repo-5-3.noarch.rpm

commands:0_newrelic_command:command: "touch /tmp/$(date '+%F.%T.%N').newrelic_command_0"

1_configure_new_relic_key:command: nrsysmond-config --set license_key=<Your key here>

1a_newrelic_command:command: "touch /tmp/$(date '+%F.%T.%N').newrelic_command_1a"

2_start_new_relic:command: "/etc/init.d/newrelic-sysmond start"

2a_newrelic_command:command: "touch /tmp/$(date '+%F.%T.%N').newrelic_command_2a"

Zero-downtime deployments

Swap URLs

1. Create a new environment for an existing application

2. Deploy your updated application code to the new environment

3. Use the “Swap URLs” feature to transition users to the new

production environment

Updating AWS Elastic Beanstalk Environments with Rolling Updates

Or …

Or …

Deploying Application Versions in Batches

Benefits of Elastic Beanstalk

Focus on your application

Focus on what makes your business unique

Focus on innovation, not undifferentiated heavy lifting

Spend developer time in the right place

Automate as much as you can

There’s no additional charge for Elastic Beanstalk

Demonstrationwww.example.com

Amazon Route 53

DNS service

Availability Zone a Availability Zone b

Servers

Elastic Load

Balancing

RDS DB

instance

ElastiCache

node 1

RDS DB

standby

ElastiCache

node 2

Servers