0
0
AWScloud~5 mins

Right-sizing resources in AWS - Commands & Configuration

Choose your learning style9 modes available
Introduction
Right-sizing resources means choosing the best size and type of cloud resources like servers or databases to match your needs. This helps avoid paying too much for unused power or having too little power to run your apps smoothly.
When your cloud server is often idle but you still pay for it.
When your app slows down because the server is too small.
When you want to save money by using only what you need.
When you want to improve app performance by upgrading resources.
When you want to plan for future growth without waste.
Commands
This command fetches the average CPU usage of an EC2 instance over one day to see how much processing power it uses.
Terminal
aws cloudwatch get-metric-statistics --namespace AWS/EC2 --metric-name CPUUtilization --dimensions Name=InstanceId,Value=i-0123456789abcdef0 --start-time 2024-06-01T00:00:00Z --end-time 2024-06-02T00:00:00Z --period 3600 --statistics Average
Expected OutputExpected
{ "Label": "CPUUtilization", "Datapoints": [ {"Timestamp": "2024-06-01T01:00:00Z", "Average": 12.5}, {"Timestamp": "2024-06-01T02:00:00Z", "Average": 15.3}, {"Timestamp": "2024-06-01T03:00:00Z", "Average": 10.1} ] }
--namespace - Specifies the AWS service to get metrics from
--metric-name - Specifies the metric to retrieve
--dimensions - Filters metrics by resource ID
--start-time - Start of the time range for metrics
--end-time - End of the time range for metrics
--period - Granularity of data points in seconds
--statistics - Type of statistic to retrieve
This command changes the EC2 instance type to a medium size, adjusting resources to better fit the workload based on usage data.
Terminal
aws ec2 modify-instance-attribute --instance-id i-0123456789abcdef0 --instance-type t3.medium
Expected OutputExpected
No output (command runs silently)
--instance-id - Specifies which instance to modify
--instance-type - Sets the new instance size
This command checks the current configuration of the EC2 instance to confirm the new size is applied.
Terminal
aws ec2 describe-instances --instance-ids i-0123456789abcdef0
Expected OutputExpected
{ "Reservations": [ { "Instances": [ { "InstanceId": "i-0123456789abcdef0", "InstanceType": "t3.medium", "State": {"Name": "running"} } ] } ] }
--instance-ids - Specifies which instance to describe
Key Concept

If you remember nothing else from this pattern, remember: monitor your resource usage first, then adjust size to match actual needs to save money and improve performance.

Common Mistakes
Changing instance size without checking current usage metrics.
You might pick a size too big or too small, wasting money or hurting performance.
Always check usage data like CPU or memory before resizing.
Not stopping the instance before changing certain instance types.
Some instance types require the instance to be stopped before resizing, or the command will fail.
Stop the instance first using 'aws ec2 stop-instances' before modifying the instance type if needed.
Summary
Use CloudWatch metrics to monitor resource usage like CPU before resizing.
Modify the instance type to better fit your workload based on usage data.
Verify the change by describing the instance to confirm the new size.