Amazon EC2 (Elastic Compute Cloud) is a web service that provides resizable compute capacity in the cloud. It allows users to create and manage virtual machines, commonly referred to as “instances”, which can be launched in a matter of minutes and configured with custom hardware, network settings, and operating systems.
Under Application and OS Images (Amazon Machine Image), do the following:
Under Instance type, from the Instance type list, you can select the hardware configuration for your instance. Choose the t2.micro
instance type, which is selected by default. In Regions where t2.micro
is unavailable, you can use a t3.micro
instance.
Under Key pair (login), choose create new key pair the key pair that you created when getting set up.
For Name, enter a descriptive name for the key pair. Amazon EC2 associates the public key with the name that you specify as the key name.
For Key pair type, choose either RSA.
For Private key file format, choose the format in which to save the private key. Since we will use ssh
to connect to the machine, choose pem.
Choose Create key pair.
Important
This step should be done once! once you’ve created a key-pair, use it for every EC2 instance you are launching.
The private key file is automatically downloaded by your browser. The base file name is the name you specified as the name of your key pair, and the file name extension is determined by the file format you chose. Save the private key file in a safe place.
Important
This is the only chance for you to save the private key file.
Your private key file has to have permission of 400
, chmod
it if needed.
Keep the default selections for the other configuration settings for your instance.
Review a summary of your instance configuration in the Summary panel, and when you’re ready, choose Launch instance.
A confirmation page lets you know that your instance is launching. Choose View all instances to close the confirmation page and return to the console.
On the Instances screen, you can view the status of the launch. It takes a short time for an instance to launch. When you launch an instance, its initial state is pending
. After the instance starts, its state changes to running
and it receives a public DNS name.
Open the terminal in your local machine, and connect to your instance by:
ssh -i "</path/key-pair-name.pem>" ubuntu@<instance-public-dns-name-or-ip>
An Amazon Machine Image (AMI) is a pre-configured virtual machine image used to create EC2 instances. AMIs contain all the information needed to launch a new instance, including the operating system, application server, and any additional software. AMIs provide a fast and reliable way to launch instances with specific configurations, making it easy to replicate complex environments or deploy new instances with consistent configurations.
When you stop an instance, AWS shut it down. They don’t charge usage for a stopped instance, or data transfer fees, but do charge for the storage for any Amazon EBS volumes.
Each time you start a stopped instance, you are charged with a minimum of one minute for usage. After one minute, AWS charge only for the seconds you use.
For example, if you run an instance for 20 seconds and then stop it, AWS charges for a full one minute. If you run an instance for 3 minutes and 40 seconds, you are charged for exactly 3 minutes and 40 seconds of usage.
If you decide that you no longer need an instance, you can terminate it.
In the navigation pane, choose Instances and select the instance.
Choose Instance state, Stop instance. If this option is disabled, either the instance is already stopped or its root device is an instance store volume.
When prompted for confirmation, choose Stop. It can take a few minutes for the instance to stop.
(Optional) While your instance is stopped, you can modify certain instance attributes. For more information, see modify-stopped-instance.
To start the stopped instance, select the instance, and choose Instance state, Start instance.
It can take a few minutes for the instance to enter the running
state.
Amazon Elastic Block Store (EBS) is a block-level storage service designed to provide durable and scalable storage for Amazon EC2 instances. EBS volumes can be attached to EC2 instances as block devices, and can be used for a variety of use cases such as storing application data, databases, and backups. EBS volumes are highly available and reliable, and provide features such as snapshotting and encryption for enhanced data protection.
Suppose after six months of using your EC2 instance, you run out of storage space on your data volume. You decide to double the size of your data volume. To do this, first you create a snapshot (this is a good practice!), and then you increase the size of the data volume.
Create a snapshot of the data volume, in case you need to roll back your changes.
In the Amazon EC2 console, in the navigation pane, choose Instances, and select your instance.
On the Storage tab, under Block devices select the Volume ID of the data volume.
On the Volumes detail page, choose Actions, and Create snapshot.
Under Description, enter a meaningful description.
Choose Create snapshot.
To increase the data volume size, in the navigation pane, choose Instances, and select your instance.
Under the Storage tab, select the Volume ID of your data volume.
Select the check box for your Volume ID, choose Actions, and then Modify volume.
The Modify volume screen displays the volume ID and the volume’s current configuration, including type, size, input/output operations per second (IOPS), and throughput. In this tutorial you double the size of the data volume.
For Volume type, do not change value.
For Size, change to 16 GB.
For IOPS, do not change value.
For Throughput, do not change value.
Choose Modify, and when prompted for confirmation choose Modify again. You are charged for the new volume configuration after volume modification starts. For pricing information, see Amazon EBS Pricing.
Note
You must wait at least six hours and ensure the volume is in the in-use
or available
state before you can modify the volume again.
Once the data volume enters the optimizing
state, you can use file system-specific commands to extend the file system to the new, larger size.
For more information about extending the file system, see Extend a Linux file system after resizing a volume.
To extend the file system
[ec2-user ~]$ df -hT
The following example output shows that the file system size of the data volume /dev/nvme1n1
is 8 GB. In the previous procedure, you increased the data volume size to 16 GB. Now you need to extend the file system to take advantage of the added storage.
Use the following command to extend the XFS file system that is mounted on the /data
mount point.
[ec2-user ~]$ sudo xfs_growfs -d /data
Use the following command again to verify that the file system has been extended.
[ec2-user ~]$ df -hT
The following example output shows that the file system size of /dev/nvme1n1
is the same as the data volume size.
SSD gp3
. For more information, see Amazon EBS volume types.scp
to copy the files in our shared repo under simple_flask_webserver
from your local machine to the instance.python3 app.py
(install requirements if needed).Enter the interactive self-check page
Explore the pricing page of on-demand instances.
Compute the monthly cost of the below instance characteristics:-
us-east-1
.*.micro
instance.8GGB
of SSD gp3 EBS.50GB
of data transferred into the instance.600GB
of data transferred from the instance to S3.230GB
of data transfer out of the instance to customers around the world.8TB
of data transferred from the instance to other instances in the same AZ.1TB
of data transferred from the instance to another region.Perform the below operations using AWS cli directly on your instance.
ENV=test
to your instance.*.micro
to *.nano
.boto3
boto3
is the AWS SDK for Python, which allows Python developers to write software that makes use of AWS services.
pip install boto3
(it’s recommended to install it using PyCharm’s terminal in an existing Python venv).Work with a friend on the same region.
Use the iperf
tool to measure network performance between two EC2 instances.
You’ll measure the bandwidth and latency of the connection using the iperf
output.
iperf
on both you and your friend machine:sudo apt-get update
sudo apt-get install iperf3
iperf3 -s
iperf3 -c <SERVER_IP>
Make sure the appropriate ports are opened.
sudo xfs_admin -U generate <device-name>
/etc/fstab
:
UUID=<device-uuid> /data xfs defaults,nofail 0 2
while <device-uuid>
is your generated device UUID.
Make sure the data from the unencrypted volume has been migrated successfully to the encrypted volume.
EC2 instance metadata is a service provided by AWS that allows an EC2 instance to retrieve information about itself (from within itself), such as its instance ID, hostname, and IP address, without the need for authentication. This information can be accessed using a special URL or by using the EC2 instance metadata service API.
There is a static IP address reserved by AWS to retrieve instance metadata:
http://169.254.169.254/latest/meta-data/
Connect to your instance, and use curl
and the instance metadata URL to retrieve: