LAB 1 EC2-3_09_03_2023 (1)

docx

School

Northern Kentucky University *

*We aren’t endorsed by this school

Course

371

Subject

Computer Science

Date

Apr 3, 2024

Type

docx

Pages

7

Uploaded by Lukem11568

Report
CIT438/538 Lab#1: AWS EC2 You will use the CLI to manage the Amazon EC2 service. You will use the CLI commands to launch instances, manipulate security groups, and more. Tools and Materials 1. One Ubuntu VM on the vSphere server 2. AWS credentials 3. AWS CLI Note: You need to replace words in bold with your information. Questions will be in red. Part 1: Creating a security group and a key pair 1. Start your VM image on the vSphere server. Log in as cit438 with password cit438. 2. Create a security group and use your NKU username to name your security group via the following command: aws ec2 create-security-group --group-name your_username --description "my security group" What’s the output? “GroupId”: “sg-0dadc9864lle6640” 3. Add rules to the security group. Define two rules that allow incoming traffic over port 22 and port 80 for SSH and HTTP and add them to your security group via the following commands: aws ec2 authorize-security-group-ingress --group-name your_username --protocol tcp --port 22 --cidr 0.0.0.0/0 aws ec2 authorize-security-group-ingress --group-name your_username --protocol tcp --port 80 --cidr 0.0.0.0/0 You can verify if the rules are added properly to your security group via the following command: aws ec2 describe-security-groups --group-names your_username
What’s the output? To:Mason Luke Thu 1/18/2024 7:50 PM { "SecurityGroups": [ { "Description": "my security group", "GroupName": "Lukem1", "IpPermissions": [ { "FromPort": 80, "IpProtocol": "tcp", "IpRanges": [ { "CidrIp": "0.0.0.0/0" } ], "Ipv6Ranges": [], "PrefixListIds": [], "ToPort": 80, "UserIdGroupPairs": [] }, { "FromPort": 22, "IpProtocol": "tcp", "IpRanges": [ { : 4. A key pair will be used when connecting to an EC2 instance. You can use the following command to create and save the key pair: aws ec2 create-key-pair --key-name your_username -key --query 'KeyMaterial' --output text > your_username-key .pem Did you see your_username-key.pem under your current directory? Is your_username- key.pem your private key or your public key? Yes I saw the Lukem1-key.pem under my current directory, and it is my private key You need to modify permissions to the your_username-key.pem file so that only you can access it. chmod 400 your_username-key.pem
Part 2: Instantiating an image 5. To start an instance, you can run the following command: aws ec2 run-instances --image-id ami-013f17f36f8b1fefb --count 1 --instance-type t1.micro -- key-name your_username -key --security-groups your_username What’s the output? What’s your instance ID? { "Groups": [], "Instances": [ { "AmiLaunchIndex": 0, "ImageId": "ami-013f17f36f8b1fefb", "InstanceId": "i-0b8095666ec947692", "InstanceType": "t1.micro", "KeyName": "Lukem1-key", "LaunchTime": "2024-01-19T00:57:38+00:00", "Monitoring": { "State": "disabled" }, "Placement": { "AvailabilityZone": "us-east-1c", "GroupName": "", "Tenancy": "default" }, "PrivateDnsName": "ip-172-31-35-29.ec2.internal", "PrivateIpAddress": "172.31.35.29", "ProductCodes": [], "PublicDnsName": "", "State": { "Code": 0, The InstanceId": "i-0b8095666ec947692" 6. You need the instance’s public IP address or public DNS name to access the instance. After waiting for 30 seconds, you can use the following command to find out the network information: aws ec2 describe-instances --instance-ids your_instance_id What’s the output? What is the public IP address of your instance? { "Reservations": [ { "Groups": [], "Instances": [ {
Your preview ends here
Eager to read complete document? Join bartleby learn and gain access to the full version
  • Access to all documents
  • Unlimited textbook solutions
  • 24/7 expert homework help
"AmiLaunchIndex": 0, "ImageId": "ami-013f17f36f8b1fefb", "InstanceId": "i-0b8095666ec947692", "InstanceType": "t1.micro", "KeyName": "Lukem1-key", "LaunchTime": "2024-01-19T00:57:38+00:00", "Monitoring": { "State": "disabled" }, "Placement": { "AvailabilityZone": "us-east-1c", "GroupName": "", "Tenancy": "default" }, "PrivateDnsName": "ip-172-31-35-29.ec2.internal", "PrivateIpAddress": "172.31.35.29", "ProductCodes": [], "PublicDnsName": "ec2-54-157-46-133.compute-1.amazonaws.com", : The ip address : "PrivateIpAddress": " 54.157.46.133 ", Part 3: logging in to your instance 7. You can use the following ssh command to connect to the instance: ssh -i your_username -key.pem ubuntu@ the_public_IP_address_of_your_instance If you see “Are you sure you want to continue connecting (yes/no)?”, please type “yes” to continue. When you see the prompt, type “sudo –s” to switch to the root. 8. Please run “cat /proc/meminfo” and “cat /proc/cpuinfo” on a terminal of your instance. What is the CPU frequency of your instance? What is the memory size of your instance? Please run “uname -a”. Is your instance a 32-bit platform or a 64-bit platform? The cpu is frequency is 2294.608 MHz The memory size is 3880496 kB, which is approximately 3.88 GB The platform is a 64-bit 9. Please run the following commands to install and start an apache web server on your EC2 instance: apt-get update apt-get install apache2
apachectl restart Then you can enter the following command to see if your server is up and running properly: systemctl status apache2 10. Start a browser and type “http:// the_public_IP_address_of_your_instance /” to access to the Apache web server in your instance. What did you see in your browser? Please give me a screen capture of your browser. Part 4: Terminating an instance You will be billed as long the instance is running, so you will need to shut it down when you're done. 11. Start another terminal in your VM and run the following command to terminate your instance: aws ec2 terminate-instances --instance-ids your_instance_id What is the output? { "TerminatingInstances": [
{ "CurrentState": { "Code": 32, "Name": "shutting-down" }, "InstanceId": "i-0b8095666ec947692", "PreviousState": { "Code": 16, "Name": "running" } } ] } Part 5: Instantiating an image with customized data 12. We manually installed the Apache web server in step 10. Let’s create a shell script called apache-install.sh under your current directory. The content of apache-install is as follows: #!/bin/bash # Prevent apt-get from bringing up any interactive queries export DEBIAN_FRONTEND=noninteractive # Upgrade packages apt-get update # Install Apache apt-get install apache2 -y You can use the --user-data   option of the run-instances command to automatically run a shell script during the instance launch time. The following is the run-instances command: aws ec2 run-instances --image-id ami-013f17f36f8b1fefb --count 1 --instance-type t1.micro -- key-name your_username -key --security-groups your_username --user-data file://apache- install .sh 13. Log onto the instance and switch to the root. Then run the following command to verify if the Apache server is installed and running. systemctl status apache2 14. Please terminate the instance. What command did you use to terminate the instance?
Your preview ends here
Eager to read complete document? Join bartleby learn and gain access to the full version
  • Access to all documents
  • Unlimited textbook solutions
  • 24/7 expert homework help
aws ec2 terminate-instances --instance-ids i-0b8095666ec947692 Submission instruction After completing this work, submit this word document with your answers to the Canvas. In your word document, your answers should be in blue print.