Today I was learning about AWS Elastic Beanstalk, here are the notes:
Elastic Beanstalk
- Is the Heroku of AWS
- CloudFormation templates
Platforms
- Docker
- Multi-docker
- Go, Ruby, Python, Node, PHP, .NET (and frameworks)
Web vs Worker
- Web directly to internet
- Worker for background jobs
Web environments
Load-balanced environment
- Uses ASG and set to scale
- Uses ELB
Single-instance environment
- Uses a Public IP address
- No ELB to reduce costs
Deployent policies availables with Elastic Beanstalk
Deployment Policy | Load Balanced Env | Single Instance Env |
---|---|---|
All at once | ✅ | ✅ |
Rolling | ✅ | 🚫 |
Rolling with aditional batch | ✅ | 🚫 |
Inmutable | ✅ | ✅ |
* rolling requires an ELB
All at once deployment
- Deploys new app version to all instances at the same time.
- Takes all insttances
out of service
while deployment process. - Servers become available again.
Fastest but dangerous deployment method. In case of failure: You need to roll-back and redeploy original version.
Rolling deployment
- Deploys the new app version to a batch of instances at a time.
- Takes batch’s instances
out of services
while the deployment process. - Reattaches updated instances.
- Repeat with next batches
In case of failure: You need to perform an aditional rolling update in order to roll-back the changes.
Rolling with aditional batch
- Launches new instance tha will be used to replace a batch.
- Deploy update app version to new batch.
- Attach new batch and terminate the existing batch.
- Rolling with additional batch ensure our capacity is never reduced.
- Important for applications were a reduction on capasity could cause availability issues.
In case of failure: Perform aditional rolling update to roll-back changes.
Inmutable
- Create a new ASG group with EC2 instances.
- Deploy the updated version o the new EC2 instances.
- Point the ELB to the new ASG and delete old ASG (which will terminate old EC2 instances).
- Safest way to deploy critical applications.
In case of failure: Terminate new instances since the existing will remain.
Deployment methods
Method | Impact of failed deployment | Deploy time | No downtime | No DNS change | Roll-back process | Code deployed to instances |
---|---|---|---|---|---|---|
All at once | Downtime | ⏱ | 🚫 | ✅ | Manual | Existing |
Rolling | Single batch out of service; any succesfull baches before failure running new version | ⏱⏱+ | ✅ | ✅ | Manual | Existing |
Rolling with aditional batch | Minimal if first batch fail; otherwise similar to rolling | ⏱⏱⏱+ | ✅ | ✅ | Manual | New and Existing |
Inmutable | Minimal | ⏱⏱⏱⏱ | ✅ | ✅ | Terminate new | New |
Blue/green | Minimal | ⏱⏱⏱⏱ | ✅ | 🚫 | Swap URL | New |
In-place vs Blue/Green
Elastic Beanstalk by default perform in-place updates.
Elastic Beanstalk configuration files
.ebextennsions
-> hidden folder at the root of the project.config
-> extension of the files inside.ebextensions
Configuration files can config
- Option settings
- Linux / Windows server config
- Custom resources
Environment manifest
Is a file called env.yml
which is stored on the root of the project.
1
2
3
4
5
6
7
8
AWSConfigurationTempalteVersion: 1.1.0.0
EnvironmentName: application-prod
SolutionStack: Ruby
EnvironmentLinks:
WORKERQUEUE: "worker+"
OptionSettings:
asw:elb:loadbalancer:
CrossZone: true
Linux Server Configuration
Packages
Download and install prepackaged applications and components
1
2
3
4
packages:
yum:
libmemcached: []
ruby-devel: []
Groups
Create Linux/UNIX groups and to assign group IDs
1
2
3
4
groups:
groupAdmin: {}
groupDev:
gid: "12"
Users
Create Linux/UNIX users
1
2
3
4
5
6
users:
mijail:
groups:
- groupAdmin
uid: 87
homeDir: "/home/mijail/"
Files
Create files on the EC2 instance (inline or from URL)
1
2
3
4
5
6
7
files:
"/home/mijail/application.yml":
mode: "000755"
owner: root
group: root
content: |
SECRET: RandomSecret
Commands
Execute commands on the EC2 instance before app is setup
1
2
3
4
5
commands:
1_create_root:
command: mkdir /var/www/app
2_link:
command: ln -s /var/www/app /app
Services
Define which services sould be started or stoped when the instance is lauched.
1
2
3
4
5
services:
sysvinit:
nginx:
enabled: true
ensureRunning: true
Container Commands
Execute commands that affect your application source code. Not refered to docker containers, just application code.
1
2
3
4
5
container_commands:
0_migrate:
command: rake db:migrate
1_assets:
command: rake assets:precompile
Elastic Beanstalk CLI
eb init
-> configure your project directoryeb create
-> create enveb status
-> see current status of enveb health
-> view health info for the instances and overall enveb events
-> list of events output by EBeb logs
-> pull logs from a instanceeb open
-> open env website in a browsereb deploy
-> once the env is runnig deploy an updateeb config
-> take a look at the configuration options available on the running enveb terminate
-> delete the environment
Elastic Beanstalk Custom Images
When you crete an EB environment you can specify an AMI to use insted of the standart EB AMI
Configuring RDS
- Inside EB
- Outside EB
Inside EB Env
- Generally for
development
envs - When the EB env is terminated the DB is also terminated
Outside EB env
- Intended for
production
environments - Create the db form RDS separate from EB
- When de EB env is termitaded the DB will remain
Elastic Beanstalk cheat sheet
- Handles deployment from capacity provisioning, load balancing, auto-scaling to application health monitoring.
- When you want to run a web-application but you don’t want to have think about the underlying infrastructure.
- It cost nothing to use Elastic Beanstalk (only resources it provisions eg. RDS, ELB, EC2)
- Recommended for test or development apps. Not recommended for production use (super large enterprises)
- You can choose from the following preconfigured platforms: Java, .NET, PHP, Node, Python, Ruby, Go and Docker.
- You can run containers on EB either in Single-container or Multi-container, thes containers are running on ECS instead of EC2.
- You can launch either a Web Environment or a Worker Environment.
- Web Environments comes in two types Single-Instance or Load Balanced.
- Single-Instance env launches a single EC2 instance, an EIP is assigned to the EC2.
- Load Balanced Env launch EC2s behind an ELB managed by an ASG.
- Worker environments creates an SQS queue, install the SQS deamon on the EC2 instances, and has ASG scaling policy which will add or remove instances based on the queue size.
- Web Environments comes in two types Single-Instance or Load Balanced.
- EB has the following deployment policies:
- All at once takes all sercers
out of service
, applies changes, put the servers back in service, fast, has downtime. - Rolling updates servers in batches, reduced capacity based on batch size.
- Rolling with additional batch adds new servers in batches to replace old, never reduces capacity.
- Inmutable creates the same amount of servers, and switches all at once to new servers, removing old servers.
- All at once takes all sercers
- Rolling deployment policies require an ELB so cannot be used with Single-Instance Web environments.
- In-Place deployment is when deployment occurs within the environment, all deployment policies are In-Place.
- Blue/Green is when deployment swaps environments (outside an environment), When you have external resources such as RDS which cannot be destroyet its suited for Blue/Green.
.ebextensions
is a folder which contains all configuration files.- With EB you can provide a Custom Image which can imporve provisioning times.
- If you let EB create the RDS instance, that means when you delete your environment it will delete the database. This setup is intended for development and test environments.
- Dockerrun.aws.json is similar to a ECS task definition files and defines multicontainer configuration.