Hands-On Lab: Optimizing AWS Resource Performance and Costs
Unit 7: Performance and Cost Optimization
Hands-On Lab: Optimizing AWS Resource Performance and Costs
This lab provides a guided experience in identifying performance bottlenecks and cost inefficiencies within an AWS environment. You will act as a CloudOps Engineer tasked with rightsizing compute resources, optimizing storage performance, and implementing cost controls using AWS native tools.
[!WARNING] Remember to run the teardown commands at the end of this lab to avoid ongoing charges for provisioned resources.
Prerequisites
- AWS Account: An active AWS account with
AdministratorAccessor equivalent IAM permissions. - CLI Tools: AWS CLI installed and configured with a profile. Run
aws configureto set up your credentials. - Resources: Ensure you have at least one running EC2 instance (e.g.,
t3.micro) with an attached EBS volume to perform modifications. If you don't, create one before starting Step 2. - Knowledge: Basic understanding of EC2, EBS, and IAM.
Learning Objectives
By the end of this lab, you will be able to:
- Analyze rightsizing recommendations using AWS Compute Optimizer.
- Optimize EBS volume performance and cost using the AWS CLI and Console.
- Implement proactive cost monitoring using AWS Budgets.
- Analyze spend patterns using AWS Cost Explorer.
Architecture Overview
This lab interacts with the following AWS services to create a feedback loop between monitoring, analysis, and remediation.
The Optimization Lifecycle
Step-by-Step Instructions
Step 1: Analyze Compute Optimization Recommendations
Before modifying resources, we must identify which ones are over-provisioned (wasting money) or under-provisioned (hurting performance).
# List EC2 instance recommendations from Compute Optimizer
aws compute-optimizer get-ec2-instance-recommendations --region <YOUR_REGION>[!NOTE] Compute Optimizer requires at least 30 hours of CloudWatch metric data to generate meaningful recommendations. If your account is brand new, the output may be empty.
▶Console alternative
- Log in to the AWS Management Console.
- Search for and select AWS Compute Optimizer.
- Click EC2 instances in the left sidebar.
- Review the "Finding" column for statuses like
Over-provisionedorUnder-provisioned.
📸 Screenshot: Look for the finding classification and the recommended instance types.
Step 2: Optimize EBS Volume Performance
In this step, we will modify an existing General Purpose SSD (gp2) volume to the newer (gp3) type, which often provides better performance at a lower cost.
# Find your volume ID
aws ec2 describe-volumes --query "Volumes[*].{ID:VolumeId,Type:VolumeType}" --output table
# Modify the volume to gp3
aws ec2 modify-volume --volume-id <YOUR_VOLUME_ID> --volume-type gp3[!TIP] gp3 volumes allow you to provision IOPS and Throughput independently of storage size, unlike gp2.
▶Console alternative
- Navigate to EC2 > Volumes.
- Select your volume.
- Select Actions > Modify volume.
- Change Volume Type to
gp3. - Click Modify and confirm.
Step 3: Configure a Monthly Cost Budget
To prevent surprise bills, we will set a budget that alerts us if our monthly spend exceeds $10.
# Note: This requires a budget definition JSON file.
# For this lab, we will use the Console as the CLI syntax for Budgets is highly complex.▶Console Instructions
- Search for AWS Budgets.
- Click Create budget.
- Choose Cost budget (Recommended).
- Set the Budget name to
Monthly-Lab-Limit. - Set Budget amount to
$10.00. - Under Alerting, add an alert at 80% of the budget ($8.00) and enter your email address.
- Click Create budget.
Checkpoints
- Compute Optimizer: Did you see any instances listed? (If not, why? Hint: Metric duration).
- EBS State: Run
aws ec2 describe-volumes --volume-ids <ID>and verify theStateismodifyingorin-useand type isgp3. - Budget Status: Does your budget show in the AWS Budgets dashboard with a green status?
Troubleshooting
| Problem | Potential Cause | Fix |
|---|---|---|
| AccessDenied when running CLI | Insufficient IAM permissions | Attach the AdministratorAccess policy or specific service policies (EC2, Budgets). |
| Volume modification fails | Volume is currently being modified | Wait for the previous modify-volume task to reach 100% or completed state. |
| No data in Cost Explorer | New Account | Cost Explorer data takes up to 24 hours to populate after enabling. |
Clean-Up / Teardown
To ensure no additional costs are incurred, delete the resources used during this lab.
- Delete Budget:
bash
# CLI deletion requires Account ID aws budgets delete-budget --account-id <YOUR_ACCOUNT_ID> --budget-name Monthly-Lab-Limit - Terminate EC2 Instances: If you created a test instance, terminate it now.
bash
aws ec2 terminate-instances --instance-ids <YOUR_INSTANCE_ID> - Delete Volumes: If you have unattached EBS volumes, delete them to save costs.
Cost Estimate
- EC2 (t3.micro): ~$0.0104/hour (Free Tier eligible).
- EBS (gp3): $0.08/GB-month (Free Tier eligible up to 30GB).
- AWS Budgets: First 2 budgets are free.
- Compute Optimizer: Free for standard EC2 metrics.
Total Lab Cost: Typically $0.00 if within Free Tier limits, otherwise < $0.10.
Concept Review
| Service | Primary Use in Optimization |
|---|---|
| Compute Optimizer | Rightsizing recommendations based on historical usage. |
| Cost Explorer | Visualizing spend trends and identifying anomalies. |
| AWS Budgets | Proactive alerting based on defined spend thresholds. |
| gp3 Volumes | Decoupling performance (IOPS) from capacity (GB) to reduce waste. |