How to Build and Manage a Resilient Service Using Health Checks, Decoupled Dependencies, and Load Balancing using AWS SDKs
Did you know you can deploy and manage a load-balanced, resilient web service entirely with AWS SDKs?
- Amazon EC2 Auto Scaling is used to create Amazon Elastic Compute Cloud (Amazon EC2) instances based on a launch template. The Auto Scaling group ensures that the number of instances is kept in a specified range.
- Elastic Load Balancing handles HTTP requests, monitors the health of instances in the Auto Scaling group, and distributes requests to healthy instances.
- A Python web server runs on each instance to handle HTTP requests. It responds with recommendations and health checks and takes different actions depending on a set of AWS Systems Manager parameters that simulate failures and demonstrate improved resiliency.
- An Amazon DynamoDB table simulates a recommendation service that the web server depends on to get recommendations.
- The DynamoDB table that is used as a recommendation service. The table is populated with a few initial values.
- An AWS Identity and Access Management (IAM) policy, role, and instance profile that grants permission to each Amazon EC2 instance so that it can access the DynamoDB recommendations table and Systems Manager parameters.
- An Amazon EC2 launch template that specifies how instances are started. The launch template includes a startup Bash script that installs Python packages and starts a Python web server.
- An Auto Scaling group that is configured to ensure that you have three running instances in three Availability Zones.
- An ELB target group that is attached to the Auto Scaling group. The target group forwards HTTP requests to instances in the Auto Scaling group on port 80, and is configured to verify the health of instances. To speed up this demo, the health check is configured with shortened times and lower thresholds. In production, you might want to decrease the sensitivity of your health checks to avoid unwanted failures.
- An Application Load Balancer that provides a single endpoint for your users, and a listener that the load balancer uses to distribute requests to the underlying instances.
- You used a load balancer to let your users target a single endpoint that automatically distributed traffic to web servers running in your target group.
- You used an Auto Scaling group so you could remove unhealthy instances and automatically keep the number of instances within a specified range.
- You decoupled your web server from its dependencies and returned a successful static response even when the underlying service failed.
- You implemented deep health checks to report unhealthy instances to the load balancer so that it dispatched requests only to instances that responded successfully.
- You used a load balancer to let the system fail open when something unexpected went wrong. Your users got a successful static response, buying you time to investigate the root cause and get the system running again.
Any opinions in this post are those of the individual author and may not reflect the opinions of AWS.