AWS EC2 supports two types of AMIs based on your root device: Instance Store-Backed and EBS-Backed. There are a number of advantages to launching an instance from an EBS-Backed AMI, including:
- Crash-consistent snapshots for persistent root and additional storage devices
- The ability to stop the instance to save on costs – stopping an instance will not incur any costs in terms of running the EC2 instance, but will for EBS storage.
- Vertical scaling. AWS EC2 allows you to modify the instance size of an EBS-backed instance so long as the instance is in a stopped state. This is very useful, allowing you to increase or decrease the size of a volume, however it requires the instance to be stopped.
- Once you have launched an EC2 instance, go to the AWS EC2 Instances section of the Amazon Management Console and select any instance. You can find the current instance type in the description area.
To perform the same step using AWS CLI, run the following command: aws ec2 describe-instances
- To stop the instance, select ‘Instance State’-> ‘Stop’ from the ‘Actions’ menu.
(Note: As noted above, the instance type can only be changed in stopped state)
Using CLI: aws ec2 stop-instances –instance-ids i-6370
- To modify the instance size, select ‘Instance Settings’->’Modify Instance Type’ from the ‘Actions’ menu. Select the appropriate size. Seeing as we have launched a medium sized instance, we will now reduce the size to ‘t2.micro’.
Using CLI: aws ec2 modify-instance-attribute –instance-id i-6370 –instance-type “{\”Value\”: \”t2.micro\”}”
- Here we can see the change to a ‘t2.micro’ instance.
Using CLI: aws ec2 describe-instances
- Once the instance size is modified, you can start the instance using the ‘Actions’ menu:
Using CLI: aws ec2 start-instances –instance-ids i-6370
Part 2:
Modifying an Instance Size Using an Automated Script As previously mentioned, it is cost effective to change instance sizes every day if your situation permits. Therefore, it’s recommended to make an automated script that can perform these tasks for you. In this section, we present scripts that will stop an instance, change its size, and restart it. You can run these scripts from local machines or a continuous running EC2 instance and set them as a cron job or set a daily schedule in Windows. It is important to note that these scripts use AWS CLI commands, so it is necessary to install AWS CLI before running the scripts. We have prepared two scripts: one PowerShell Script for Windows machines and one shell script for Linux. PowerShell Script (to change the instance size to micro): $inst_id= ‘<Enter Instance ID>’ $instance_size=’t2.micro’ $instancestate = aws ec2 stop-instances –instance-ids $inst_id $state = “Not Stopped Yet” Do { $state = (Get-EC2Instance $inst_id).Instances.State.Name “Current State = $state” Sleep -Seconds 5 } While ($state -ne “stopped”) Edit-EC2InstanceAttribute -InstanceId $inst_id -Attribute “instanceType” -Value $instance_size aws ec2 start-instances –instance-ids $inst_id- Flexible backup policies and schedules
- Consistent database backup for SQL Server, Oracle, MySQL, MongoDB and more
- Instance and data recovery across AWS regions in seconds
- “Pull” and “Push” based alerts and notifications
- Application consistent backup
- Automated backup based on Tags.
- Copy EBS Snapshots to Amazon S3 buckets