Skip to main content
Launch this lab in the IP Lab Portal, then follow the steps below in the AWS console. Open IP Lab Portal

Overview

Lab details

  1. This lab guides you through the process of utilizing AWS CloudShell to execute CLI commands. The objective is to create an EC2 instance, establish an SSH connection to the instance, and subsequently install the Apache web server.
  2. Duration of the Lab: 45 minutes
  3. AWS Region: US East (N. Virginia) us-east-1

Introduction

What is AWS Cloud Shell?

AWS CloudShell is a browser-based shell that makes it easy to manage, explore, and interact securely with your AWS resources. With CloudShell, you can quickly run scripts with the AWS Command Line Interface (AWS CLI), experiment with AWS service APIs using the AWS SDKs, or use a range of other tools

Advantages :

  1. CloudShell inherits the credentials of the user signed in to the AWS Management Console.
  2. A fully managed Amazon Linux 2 environment that has the latest versions of popular tools already installed and updated.
  3. With 1 GB of persistent storage per Region, you can store scripts, files, configuration preferences, etc in your home directory.

Architecture diagram

Task details

  1. Sign into AWS Management Console
  2. Create an Environment in CloudShell
  3. AWS CLI Command to create a KeyPair
  4. AWS CLI Command to create a Security group
  5. AWS CLI Command to launch an EC2 Instance
  6. SSH into EC2 and install Apache
  7. Validation of the Lab
  8. Deleting AWS Resources.

Launching the lab environment

  1. To launch the lab environment, Click on the Launch lab button.
  2. Please wait until the cloud environment is provisioned. It will take less than a minute to provision.
  3. Once the Lab is started, you will be provided with IAM user name, Password, Access Key, and Secret Access Key.
You can only start one lab at any given time

Lab guide

Lab steps

Task 1: Sign in to the AWS Management Console

  1. Click on the Open console button, and you will get redirected to AWS Console in a new browser tab.
  2. On the AWS sign-in page,
  • Leave the Account ID as default. Never edit/remove the 12-digit Account ID present in the AWS Console. otherwise, you cannot proceed with the lab.
  • Now copy your User Name and Password in the Lab Console to the IAM Username and Password in the AWS Console and click on the Sign in button
  1. Once Signed In to the AWS Management Console, Make the default AWS Region as US East (N. Virginia) us-east-1.
Note: There is no Validation function for this lab.

Task 2: Create an Environment in CloudShell

  1. Make sure you are in the N.Virginia Region.
  2. Click on the Cloud Shell icon on the top right AWS menu bar.
  1. You will see a creating environment message on the screen.
  2. Wait for a few minutes to complete the environment creation. Once the environment is created, You are ready to use the terminal.

Task 3: AWS CLI command to create a Key Pair

  1. ?To configure credentials paste the below command and provide credentials from lab overview page.
aws configure
  1. Provide access key, secret key and region as us-east-1 and for Default output format hit enter.
  1. This command will create a Key Pair in the us-east-1 region.
  • Note: If you try to execute the command more than once, it will throw an error that the MyEC2Key.pem file exists.
  1. You won’t get any output for this CLI Command, once you have successfully created a key pair.
5.The above command creates a Key pair and stores the key in a PEM file. You can list all the directories and files to view the file. ls

Task 4: AWS CLI command to create a Security Group

  1. The below command will create a Security Group in the us-east-1 region.
  1. You will have a Group ID as output for this command, which means you have successfully created a Security Group. Type wq if : appears
  1. Add SSH port rule in inbound
  • Syntax :
  • Replace the Security Group ID with the Group ID you got in the above step to create a security group.
  • Example : aws ec2 authorize-security-group-ingress —group-id sg-023ce9d45c379afbe —protocol tcp —port 22 —cidr 0.0.0.0/0
  1. Add HTTP port rule in inbound
    • Syntax :
    • Replace the Security Group ID with the Group ID you got in the above step to create a security group.
    • Example : aws ec2 authorize-security-group-ingress —group-id sg-023ce9d45c379afbe —protocol tcp —port 80 —cidr 0.0.0.0/0

Task 5: AWS CLI command to launch an EC2 Instance

  1. The below command will create one t2.micro EC2 instance with Amazon Linux 2023 kernel-6.1 AMI in the us-east-1 region. Type wq if : appears.

Task 6: SSH into EC2 and install Apache

  1. Navigate to EC2 by clicking on the Services menu at the top, then click on EC2 in the Compute section.
  2. Navigate to Instances in the left panel.
  3. You will be able to see the EC2 instance which you have launched through CLI Command.
  4. Click on the instance ID and copy the IPv4 Public IP address of your instance and place it in your text editor
  1. Navigate back to the CloudShell browser tab.
  2. Change the permission of KeyPair.
  1. To SSH into the EC2 instance, copy & paste the following command and replace the IP address with your EC2’s Public IP address.
  • Syntax :
  • Example : ssh ec2-user@52.23.205.128 -i MyEC2Key.pem
  • Here’s the output :
  • If you get a prompt to confirm the connection enter yes
  1. Install Apache and Add a webpage (run the commands one by one).
  1. Now open a new tab in your browser, copy and paste the IPv4 Public IP of your Instance, and hit [enter]. You will be able to see the below web page.
  1. Now to return to CloudShell for your EC2 Instance, Enter exit and hit [Enter] again Enter exit and hit [Enter].
Do you know?The AWS CLI allows you to perform actions even without an active internet connection by using local caching and offline mode, which can be helpful in certain scenarios.

Task 7: Validation of the Lab

  1. Once the lab steps are completed, please click on the Check my work button on the left side panel.
  2. This will validate the resources in the AWS account and displays whether you have completed this lab successfully or not.
  3. Sample output :

Task 8: Delete AWS Resources

7.1 AWS CLI command to Delete the EC2 instance
  1. Use the aws configure to locate the credentials. Paste the Access Key and Secret Key. These keys are available under the Open console button while starting the lab.
  2. Syntax :
  3. Example : aws ec2 terminate-instances —instance-ids i-0557e626ed160301b —region us-east-1
Note: Replace the instance ID with your ID.
  1. Once you see the below output, your EC2 instance has started to terminate.
  1. Now navigate to your EC2 dashboard and you will be able to see that the EC2 instance state changed to Shutting-down/ Terminated.
8.2 Deleting the CloudShell directory
  1. Navigate to the CloudShell tab.
  2. Click on the Actions button on the top right corner and select Delete AWS CloudShell home directory.
  3. Enter delete in the text input field and click on the Delete button and close the browser tab.

Completion and conclusion

  • You have successfully created an Environment in CloudShell.
  • You have successfully created a key pair via the AWS CLI command.
  • You have successfully created a Security group via the AWS CLI command.
  • You have successfully created an EC2 Instance via the AWS CLI command.
  • You have successfully SSH into the EC2 and installed Apache.
  • You have successfully terminated the EC2 Instance via the AWS CLI command.
  • You have successfully deleted the CloudShell directory.

End lab

  1. Sign out of AWS Account.
  2. You have successfully completed the lab.
  3. Once you have completed the steps click on End lab in the IP Lab Portal.

What gets checked

When you press Check my work, the platform verifies each of these:
  • Install Apache Web Server — Check whether Apache Web Server is installed in EC2 Instance or not.