Lab: Designing for Performance with Auto Scaling and ElastiCache
Design a solution to meet performance objectives
Lab: Designing for Performance with Auto Scaling and ElastiCache
This lab focuses on the "Democratize Advanced Technologies" and "Architecting for Performance" principles from the AWS Well-Architected Framework. You will build a performance-optimized environment using Amazon EC2 Auto Scaling and Amazon ElastiCache (Redis) to handle variable workloads and reduce data retrieval latency.
Prerequisites
Before starting this lab, ensure you have:
- An AWS Account with administrative permissions.
- AWS CLI installed and configured (
aws configure). - Basic knowledge of VPC Networking (Subnets, Security Groups).
- Target Region:
us-east-1(Virginia).
Learning Objectives
By the end of this lab, you will be able to:
- Deploy a purpose-built caching layer using Amazon ElastiCache.
- Configure an Elastic architecture using Launch Templates and Auto Scaling Groups (ASG).
- Implement performance monitoring using Amazon CloudWatch alarms.
- Evaluate performance design principles through hands-on implementation.
Architecture Overview
The following diagram illustrates the performant architecture you will deploy:
Step-by-Step Instructions
Step 1: Create Security Groups
We need to allow traffic between the application instances and the cache cluster.
# Create Web Security Group
aws ec2 create-security-group \
--group-name lab-web-sg \
--description "SG for Web Servers"
# Create Cache Security Group
aws ec2 create-security-group \
--group-name lab-cache-sg \
--description "SG for Redis Cache"
# Allow Web SG to talk to Cache SG on port 6379
aws ec2 authorize-security-group-ingress \
--group-name lab-cache-sg \
--protocol tcp \
--port 6379 \
--source-group lab-web-sg▶Console Alternative
Navigate to
. Create 'lab-web-sg'. Create 'lab-cache-sg' and add an Inbound Rule for Type: Redis (6379) with Source: 'lab-web-sg'.
Step 2: Deploy Amazon ElastiCache (Redis)
Following the principle of "Democratizing Advanced Technologies," we use a managed service instead of manual installation.
aws elasticache create-cache-cluster \
--cache-cluster-id lab-redis-cluster \
--engine redis \
--cache-node-type cache.t3.micro \
--num-cache-nodes 1 \
--security-group-ids <YOUR_CACHE_SG_ID>[!IMPORTANT] Replace
<YOUR_CACHE_SG_ID>with the ID returned from the previous step.
Step 3: Create Launch Template and Auto Scaling Group
This setup ensures the application can scale horizontally based on performance metrics.
# Create Launch Template
aws ec2 create-launch-template \
--launch-template-name lab-app-template \
--launch-template-data '{"ImageId":"ami-0cff7528ff583bf9a","InstanceType":"t2.micro","SecurityGroupIds":["lab-web-sg"]}'
# Create ASG
aws autoscaling create-auto-scaling-group \
--auto-scaling-group-name lab-asg \
--launch-template LaunchTemplateName=lab-app-template \
--min-size 1 \
--max-size 3 \
--desired-capacity 1 \
--availability-zones us-east-1a us-east-1bStep 4: Configure Target Tracking Scaling Policy
To meet performance objectives dynamically, we will scale based on average CPU utilization.
aws autoscaling put-scaling-policy \
--auto-scaling-group-name lab-asg \
--policy-name cpu-target-tracking-policy \
--policy-type TargetTrackingScaling \
--target-tracking-configuration '{"TargetValue": 50.0, "PredefinedMetricSpecification": {"PredefinedMetricType": "ASGAverageCPUUtilization"}}'Checkpoints
- ElastiCache Status: Run
aws elasticache describe-cache-clusters --cache-cluster-id lab-redis-cluster. TheCacheClusterStatusshould beavailable. - ASG Instances: Run
aws autoscaling describe-auto-scaling-groups --auto-scaling-group-names lab-asg. Ensure at least one instance isInService. - CloudWatch Metrics: Check the CloudWatch console to see if the
TargetTrackingalarm has been automatically created by the scaling policy.
Concept Review
| Design Principle | Implementation in Lab |
|---|---|
| Democratize Tech | Used Managed ElastiCache instead of managing our own Redis server on EC2. |
| Go Global in Minutes | Used Multi-AZ deployment for the Auto Scaling Group. |
| Elasticity | Implemented Target Tracking Scaling to respond to performance demand. |
| Monitoring | Utilized CloudWatch Metrics for automated scaling decisions. |
Performance Optimization Cycle
\begin{tikzpicture}[node distance=2.5cm, auto, >=stealth] \node [circle, draw, text width=2cm, align=center] (monitor) {Monitor Performance}; \node [circle, draw, text width=2cm, align=center, right of=monitor, xshift=2cm] (analyze) {Analyze Metrics}; \node [circle, draw, text width=2cm, align=center, below of=analyze] (optimize) {Optimize Design}; \node [circle, draw, text width=2cm, align=center, left of=optimize, xshift=-2cm] (redeploy) {Redeploy Solution};
\draw [->, thick] (monitor) -- (analyze);
\draw [->, thick] (analyze) -- (optimize);
\draw [->, thick] (optimize) -- (redeploy);
\draw [->, thick] (redeploy) -- (monitor);
\node at (2.25,-1.25) [font=\small] {CloudWatch};
\node at (2.25,-3.75) [font=\small] {Right-Sizing};\end{tikzpicture}
Troubleshooting
| Issue | Possible Cause | Fix |
|---|---|---|
| Redis Connection Timeout | Security Group mismatch | Ensure lab-cache-sg allows port 6379 from lab-web-sg. |
| ASG Not Scaling | Insufficient load | The Target Tracking policy requires sustained CPU usage > 50% to trigger. |
| Cluster Creation Stuck | Subnet Group issues | Ensure your VPC has an ElastiCache Subnet Group if not using the default VPC. |
Clean-Up / Teardown
[!WARNING] Failure to delete these resources will result in ongoing charges to your AWS account.
# 1. Delete Auto Scaling Group
aws autoscaling delete-auto-scaling-group --auto-scaling-group-name lab-asg --force-delete
# 2. Delete Launch Template
aws ec2 delete-launch-template --launch-template-name lab-app-template
# 3. Delete ElastiCache Cluster
aws elasticache delete-cache-cluster --cache-cluster-id lab-redis-cluster
# 4. Delete Security Groups (wait for instances to terminate first)
aws ec2 delete-security-group --group-name lab-cache-sg
aws ec2 delete-security-group --group-name lab-web-sgStretch Challenge
Implement Read Replicas: Modify the ElastiCache setup to use a Replication Group instead of a single cluster. This improves performance for read-heavy workloads by offloading queries from the primary node.
Cost Estimate
- EC2 (t2.micro): ~$0.0116/hour (Free Tier eligible).
- ElastiCache (cache.t3.micro): ~$0.017/hour.
- CloudWatch: Free for standard metrics used here.
- Total Estimated Spend: < $0.50 for a 1-hour lab session.