Section 17: AWS Elastic Beanstalk
How does Elastic Beanstalk work under hood with Cloud formation?
- relies on CloudFormation - can define cloudformation resources in .ebextensions to provision anything
Beanstalk Deployment Mode All at once
- stops running all instances (downtime) -fastest deployment - no additional cost
AWS Elastic Beanstalk
- used for deploying and scaling web apps and services - Upload code and beanstalk handles deployment (capacity provisioning, load balancing, and auth scaling, and health monitoring) - we have full control over config
Beanstalk Deployment Mode Blue/green
- zero downtime - create new stage env and deploy v2 there - new env can be validated indepdently and roll back
Beanstalk Deployment Mode Immutable
- zero downtime - new code deployed to new instances on temporary AG - high cost, double capacity - longest d3eployment - quick rollback in case of failures - great for prod -- all v1 terminated in temp asg and asg removed
Elastic Beanstalk Extensions
- zipfile containg our code must be deployed to elastic beanstalk - all params set in UI can be configured with code files Requirement - in .ebextensions / directory in root of src code - .config placed within that directory (yml) - able to modify defau;lt settings - aiity to add resourcers
RDS with Elastic Beanstalk
-RDS can be provisioned with Beanstalk, which is great for dev/test -This is not great for prod as the database lifecycle is tied to the Beanstalk environment lifecycle -The best for prod is to separately create an RDS database and provide our EB application with the connection string
Elastic Beanstalk Components
• Application: collection of Elastic Beanstalk components (environments, versions, configurations, ...) • Application Version: an iteration of your application code • Environment • Collection of AWS resources running an application version (only one application version at a time) • Tiers: Web Server Environment Tier & Worker Environment Tier • You can create multiple environments (dev, test, prod)
How does Elastic Beanstalk work under the hood?
- describe depenencies (requirements.txt for python) - package code as zip - console: upload zip file and delppy - cli: create new app cli and deploy - elasrixc beanstalk will delpoy zip on each EC2 instance, resolve dependeincies and start app
Beanstalk Lifecycle Policy
- Beanstalk can store at most 1000 app versions - need to remove old versions or can't deploy - to phase out app versions, use lifecycle policy (based on time and space) - versions currently used won't be deleted
Elastic Beanstalk CLI
- CLI makes it easier for elastic beanstalk - help for automated delpoyment pipelines
Elastic Beanstalk Migration: Load Balancer
- after creating elastic beanstalk env, you can't change ELB type (only config) To migrare: 1) create new env with same config excelt LB (can't clone) 2) deploy app into new env 3) perform route 53 update
Beanstalk Deployment Mode Rolling with additional Batches
- app is running at capacity - can set bucket size - good for prod - first deploy new instances (v2) so both versions run at same time - small cost - additional batches are terminated at end
Beanstalk Deployment Mode Rolling
- app running below capacity set bucket size - roll on to next bucket (batch updates) - app is runnign both versions simultaneously - no add consts - can be long deployment based on bucket size and # of ec2 instances
Beanstalk Deployment Mode Traffic Splitting
- canary testing - new app version deployed in temp ASG with same capacity - small % of traffic is sent to temporary ASG for configurable amt time - deployment health monitored - if failurea, triggers autmoatiic rollback (very quick) - new instances are migrated from temp to original ASG and old app terminated
Elastic Beanstalk Cloning
- clone env with exact same config - useful for deploying QA env - all resources and config are preserved
How does elastic beanstalk work?
- create app - upload version - launch env - manage env
What are the deployment modes for elastic beanstalk?
1) Single Instance (one EC2 instance with elastic IP) 2) High Availability with Load Balancer (great for prod) --> multiple ec2 instances manges with ASG
AWS Beanstalk Environments
1) Web Server Environment (run website, web app or web API servingHTTPS requests) 2) Worker Environment (run worker env app that processes long running workloads on demand)
Beanstalk Deployment Modes for Updates
1) all at once (deploy all in once - fast but some downtime 2) rolling - update few instances at time (bucket) and move on when bucket healthy 3) Rolling with additional batches: like rolling but spins up new instances so old app still available 4) Immutable: spins up new instances in new asg, deploys these instances, swaps instances when healthy 5) Blue green: create new env, switch over when ready 6) Traffic Splitting: canary test0ng - sent small %
What are steps for deploying Elastic Beanstalk App?
1) configure env 2) configure service access (IAM and ECS instance profile) 3) stack created now in cloudFormation (all resoruces created for elastic beanstalk is by cloudformation)
Hw to decouple RDS if in
1) create snapshot of RDS DB 2) go to RDS console and protect RDS database from deleting 3) create a new elastic beanstalk ennv 4) perform route 53 update 5) terminate old env 6) delete cloud formation stack