How to connect to an EC2 instance
Start by creating an EC2 instance in AWS console. This can be done from the EC2 dashboard, then select Instances. In order to create a new instance, click the "Launch instances" button.
First, you will need to select an AMI. You can select any AMI from the list, but for learning purposes you might want to choose an AMI from the free tier, which will have under its name a tag with "Free tier eligible" label. Once that you have selected the AMI, click on the "Select" button which will take you to the second step, choosing the Instance Type. There are several other steps if you choose to customize your instance, but for the purpose of this tutorial, you can choose "Review and launch" option, which will take you to the last step. If you are happy with the instance configuration, click on the "Launch" button which is at the right bottom of the page. A popup window will appear. If you have created beforehand a key pair and you still have the files saved on your machine, choose your key pair from the list, otherwise create a new one and Download the key pair .cer file. You can launch your instance now, by clicking "Launch instances" button.
In your terminal, navigate to the directory where your key/pair was downloaded. The key pair is publicly viewable, so you will need to modify its permissions, by running the following command:
chmod 400 key-pair-filename.cer
In AWS console, visit Instances pages and select the instance you have just created. At the bottom of the page, you can find "Instance summary" information. From here, copy the "Public IPv4 DNS", which will have the following format:
ec2-xxx-xxx-xxx-xxx.aws-region.compute.amazonaws.com
You can now connect to your EC2 instance, by running:
ssh -i ./key-pair-filename.ce ec2-user@the_public_ipv4_dns_found_above
Congratulations, now you are connected and you can interact with your instance.
