Section 4: Elastic Load Balancing and Auto Scaling Flashcards
Scailability and Elasticity meaning
Scailability = ability to add more resource when needed
Elasticity = when no longer needed, shrinks back
Scaling Up vs Scaling Out
Scaling up = adding more resources to the instance
Scaling out = adding more instances
EC2 Auto Scaling
EC2 Auto Scaling launches and terminates instances dynamically, e.g. if CPU usage goes above/below X%
Launch template
Lunch templates specified EC2 instance config, e.g auto scaling rules, instance type, config VPN and subnets etc.
Basic vs Detailed monitoring
Basic monitoring
* 5 minute granularity
* No charge
Detailed monitoring
* 1 minute granularity
* Charges apply
Lifecycle hooks
Lifecycle hooks - used to perform custom actions by pausing instances as the Auto Scaling Group lunches or terminated them.
Use case: run a script to downlad and install software after lanching
Load balancer
Loadbalancer has 1 public endpoint address (e.g. example.com) which then distributes the traffic between multiple Web Servers (which can be in different availability zones)
Fault tolerence
Fault Tolerence = ability to recover in case of component failure. E.g. you can place web servers in two availability zones and a load balancer will route appropraitely should one server/region fail.
Types of Elastic Load Balancers (ELB)
Elastic load balancer types:
Application Load Blancer
* operates at request level
* routes based on content of the request (layer 7)
* HTTP/HTTPS protocol
* supports path-based routing, query string params routing, host-based routing, IP routing (HTTP header based routing)
* supports instances, IP addresses, contains, lambdas
* Does NOT support static IP address
Network load balancer
* operates at connection level
* routes connections on IP protocal data (layer 4)
* TCP/TLS/UDP protocol
* offers ultra high performance, low latency, TLS offloading
* Can have static / elastic IP
* Supports UDP and static IP address targets
* Does support static IP address
Gateway Load Balancer
* used in front of virtual appliances such as firewalls, IDS/IPS and deep packet insepction systems
* operates at level 3 - listens for all packets on all ports
* Uses port 6081 to exchange traffic
More info - https://aws.amazon.com/elasticloadbalancing/features/
Elastic Load Blancer uses cases
Application Load Balancer:
* web applications with L7 routing (HTTP/HTTPS)
* Microservices architectures (e.g. Docker containers)
* Lambda targets
Network load balancer
* TCP and UDP based applications
* ultra-low latency
* static IP addresses
* VPC endpoint services
Gateway Load Balancer
* Web app / next generation firewalls
* DDoS system
* intrusion detection/prevention systems
Targets and Target Groups
Targets = EC2 instances, IP addresses, Lamba functions or containers
Target Groups = used to route requests to registered targets (used in/for load balancing)
EC2 Scaling Types
EC2 Scaling Types
- Target Tracking
Adds or removes capacity as required to keep the metric at or close to the specific target value. Use when you want to keep the CPU usage of your ASG at 70% - Simple Scaling - Waits for the health check and cool down periods to expire before re-evaluating. Useful when load is erratic. AWS recommends step scaling instead of simple in most cases.
- Step Scaling - Increases or decreases the configured capacity of the Auto Scaling group based on a set of scaling adjustments, known as step adjustments. You want to vary adjustments based on the size of the alarm breach
- Scheduled Scaling - scales at defined date/time
Storing Session State
Session State data is used to ensure data persists even if an EC2 instance fails.
Session State storage is often used for session data such as authentication details stored/retrieved in a DynamoDB table. This is so users do not need to re-authenticate.
ElastiCache is also another popular solution fo storing session-state data.
Sticky Sessions
Sticky sessions on your Application Load Balancer puts a cookie on a users session so that they always use the same EC2 instance. This can aid performance as the instance can maintain or cache the session state information locally (e.g. user authentication state).
There are two types of cookies:
* load balancer generated cookie
* application-based cooke (load balancer generates this)
Beware load balancer cookies always have the same name, so if using more than 1 load balancer could causing clashing issues.
https://docs.aws.amazon.com/elasticloadbalancing/latest/application/sticky-sessions.html
Which type of scaling is provided by Amazon EC2 Auto Scaling?
Amazon EC2 Auto Scaling provides horizontal scaling