AWS Hands-On Labs - Create and Secure an EC2 Instance
AWS Learning Path for Cloud and DevOps Engineers
📝Introduction
The purpose of this Lab is to help you create an EC2 instance and allow for access only from your machine. You will then test this access to ensure that you have configured access correctly.
These are the objectives of this lab:
Configure a Security Group
Create an EC2 Instance
Test Access to the EC2 Instance
📝Log in to the AWS Management Console
Using your credentials, make sure you're using the right Region. In my case, I am using AWS as my cloud provider and chose us-east-1
.
📌Note1: You must create the AWS Access Key and AWS Secret Access Key and configure the AWS CLI in the terminal to use it.
📌Note2: At the end of each hands-on Lab, always clean up all the resources previously created to avoid being charged by your Cloud Provider to provision the resources.
You can use link1 and link2 for it.
📝Configure a Security Group
On the left side under Network & Security, click Security Groups.
In the upper right corner, click Create Security Group.
Under Basic Details, set the following values:
Security group name: <sg_name>
Description: <instance_name>.
VPC: Leave at default.
Under Inbound rules, click Add rule and set the following values:
Type: Click on the dropdown menu and select SSH.
Source: Click on the dropdown menu and select My IP.
Leave the other settings at default, scroll down, and click Create Security Group.
📝Create an EC2 Instance
On the left side under Instances, click Instances.
In the upper right corner, click Launch Instances.
Under Name and Tags, enter <instance_name>.
Under Application and OS Images (Amazon Machine Image), ensure Amazon Linux AMI is selected.
Under Instance type, click on the dropdown menu and select t3.micro.
Under Key pair (login), click Create new key pair.
In the Create key pair pop-up menu, enter <keypair_name>.
Leave the other settings at default and click Create key pair (you should see your key pair in your Downloads folder).
Next to Network settings, click Edit.
Auto-assign public IP, click on the dropdown menu and select Enable.
Under Firewall (security groups), choose Select existing security group.
Under Common Security Group, select the <sg_name> security group you just created.
Under Summary, click Launch instance.
Once the instance has launched, click View all instances.
At the top of the page in the toolbar, click on the refresh icon. You should see My Instance initializing. It may take a few minutes to run.
📝Test Access to the EC2 Instance
Click on the <your_instance> instance ID to navigate into the instance.
In the upper right corner under Private IPv4 addresses, copy the listed private IP address.
Paste the IP address in a separate text document. You'll need it later.
Under Public IPv4 address, copy the listed public IP address (paste the IP address in a separate text document, as well).
In the breadcrumb trail at the top left, click Instances.
Click on the checkbox next to <your_instance>.
In the upper right corner, click Connect.
Under User name, enter <your_username>.
Click Connect. It will fail.
Try to Access Your Machine from One of the Other Instances
Connect to My Instance (you'll need the private IP address copied earlier):
ssh <user_name>@<PRIVATE_IP_ADDRESS>
Note: This will take a few minutes, but the connection will time out. Access to the new instance should be locked down to only your machine. No other instances should be able to access that instance.
Try to Access the New Instance from Your Machine
Navigate to your Downloads folder:
cd /Users/<USERNAME>/Downloads/
Set permissions to read-only:
chmod 400 <keypair_name>.pem
Ensure permissions change was successful:
ls -al | grep key <keypair_name>.pem
Connect to (you'll need the public IP address copied earlier):
ssh -i /Users/<USERNAME>/Downloads/<keypair_name>.pem <user_name>@<PUBLIC_IP_ADDRESS>
You may get a prompt confirming access. If so, type
yes
.You should successfully connect to the instance.
📌Note - At the end of each hands-on Lab, always clean up all the resources previously created to avoid being charged if you used a Cloud Provider to provision them.
Congratulations — you have completed this hands-on lab covering the basics of creating an AWS EC2 instance and allowing for access only from your machine securely using SSH protocol.
Thank you for reading. I hope you understood and learned something helpful from my blog.
Please follow me on CloudDevOpsToLearn and LinkedIn, franciscojblsouza