AWS Beanstalk

Why it's awesome

Why should we use it

How should we use it

dev firendly, Heroku-like wrapper for AWS

Comes with Autoscaling & Loadbalancing in house

Integrates nicely with docker and aws services

And has lots of features...

Configuration management,

CloudWatch monitoring,

SSL support,

Rolling updates,

State notifications,

Robust logging system,

Sticky sessions,

Healthchecks

and more...

Application

Environment_A

Environment_B

Version_1

Version_1:latest

Version_1

Version_1:latest

Code on the machine

*Application can have multiple environments

Versions are prebuilt docker images stored on ECR

Why we should us it?

It solves some of our problems

  • Auto scaling & load balancing 
  • Rolling updates & zero-downtime deployments
  • Works well with the rest of AWS
  • After handoff, simple to use for a client
  • One step closer to IAAC -> allows to use "more" AWS

Setting up & deployment

# Setup
eb init
eb create


# Deployment
eb deploy -r <AWS_REGION>

# Logs
eb logs 

# Logs realtime
eb logs --stream

# SSH to instance
eb ssh

# Rescale
eb scale

~ ➜ eb
usage: eb (sub-commands ...) [options ...] {arguments ...}

Welcome to the Elastic Beanstalk Command Line Interface (EB CLI).
For more information on a specific command, type "eb {cmd} --help".

commands:
  abort       Cancels an environment update or deployment.
  clone       Clones an environment.
  config      Edits the environment configuration settings or manages saved configurations.
  console     Opens the environment in the AWS Elastic Beanstalk Management Console.
  create      Creates a new environment.
  deploy      Deploys your source code to the environment.
  events      Gets recent events.
  health      Shows detailed environment health.
  init        Initializes your directory with the EB CLI. Creates the application.
  labs        Extra experimental commands.
  list        Lists all environments.
  local       Runs commands on your local machine.
  logs        Gets recent logs.
  open        Opens the application URL in a browser.
  platform    Manages platforms.
  printenv    Shows the environment variables.
  scale       Changes the number of running instances.
  setenv      Sets environment variables.
  ssh         Opens the SSH client to connect to an instance.
  status      Gets environment information and status.
  swap        Swaps two environment CNAMEs with each other.
  terminate   Terminates the environment.
  upgrade     Updates the environment to the most recent platform version.
  use         Sets default environment.

What about CI/CD?

What about CI/CD?

# Setup
terraform plan -out plan.tfplan
terraform apply

# Deploy
./deploy.sh <appname> <environment> <region> <commit_sha>

                ^           ^          ^           ^
           [Same as on Beanstalk] [us-east-1] [might be gibberish]

./deploy.sh

=

1. Login to Container Registry

2. Build Image

3. Add tags to it

4. Deploy to Container Registry

5. Create new Version on beanstalk

6. Create new beanstalk task (new version with new code)

*May be executed locally or on Circle

AWS Beanstalk

By Rafal Wiliński

AWS Beanstalk

  • 552