4.3 EC2 Lab 1
Launch a EC2 instance
Choose an AMI
Choose instance type
Configure instance details
Network: VPC (virtual private cloud) is a virtual data center which you are going to provision your resources. A default VPC is created at the beginning of you create an EC2 instance. Use this default one is fine.
Subnet: one subnet is always equal to one AZ. You cannot have one subnet that goes across multiple AZs.
IAM role: choose an IAM role.
Enable termination protection: you can enable it.
Monitoring: monitor your CPU, disk IO, network, etc. Normal monitoring is done every 5 minutes. You can check this box to enable detailed monitoring, which is done every 1 minutes, but additional charges apply.
Advanced details: it allows you to do some bootstrap configuration of your EC2 instance.
Add Storage
Root volume: This root volume is used to boot your operating system. We have 3 types of root volumes, which are bootable (2 SSD + 1 HDD). You can uncheck the "Delete on Termination box" if you don't want to delete the root volume when you terminate the EC2 instance.
Other volumes (EBS): All 5 types of volumes can be used here.
It is enough to create an EC2 instance once you have a root volume.
Add Tags
Give tags to your instance. Tag is key-value pair, key could be department, value could be the name of the department. Tags can really help you to control costs and to see where your costs coming from. Tag as much as possible.
Configure Security Group
Security Group is a set of virtual firewall rules that control the traffic for your instance. You can add rules to allow specific traffic to reach your instance. Typically, you should have SSH, HTTP, HTTPS rules to be added to your security group. You can also configure the Source, you can choose Custom/My IP/Anywhere.
Review and Launch your instance
You need to select an existed key pair or create a new key pair before you launch your instance. The key pair is pair of public key and private key. The public key is a padlock, and the private key is the key that unlock that padlock. You can have same public key on multiple EC2 instances, and you can use your one private key to unlock all these padlocks. The key-pair is Region based.
After create your key pair and download your private key, you can launch the instance.
How to use your EC2 instance
Description
Public IP: this is the address that you are going to visit your EC2 instance using SSH, HTTP, etc. If you are using Windows, you should use PuTTY-gen to convert the pem private key file to ppk file (PuTTY cannot use pem file). Then you can use PuTTY and your private key to connect and log into your EC2 instance. You can type IP as "ec2-user@[ip-address]" so that you can login to your EC2 as an ec2-user, or you can type IP as "root@[ip-address]" so that you can login to as a root user. (You can also do it after you login in your instance using sudo su).
If you are using Linux, go to the folder you store your private keys, and run "CHMOD 400 [privateKey].pem" to change the permissions of the .pem file so only the root user can read it. And then run "ssh ec2-user@[ip-address] -i [privateKey].pem".
Launch a web server on your instance (just for testing purpose):
Login to your EC2 (with Amazon Linux AMI OS)
sudo su ($ -> # means you are super user now)
yum update -y
yum install httpd -y (install Apache so that your instance can be used as a web server)
cd /var/www/html (all files in this folder should be publicly accessible)
nano index.html
Hit "ctrl+X" to exit, hit "yes" to name your file and hit "enter" to save your file.
service httpd start (start your Apache server)
service httpd status (check your server's status)
chkconfig httpd on (make sure the Apache service always starts every time we reboot the instance)
Visit your web page through the public IP address of your instance.
Last updated
Was this helpful?