<h1 style='border: none'><center>Parallel and Distributed Systems Lab 3</center></h1>
<h2 style='border: none'><center>Amazon Web Service(AWS)<br>EC2 & AMI</center></h2>
<h5><center>The Islamic University of Gaza<br>Engineering Faculty<br>Department of Computer Engineering</center></h5>
<h6>Authors: Usama R. Al Zayan<span style="float:right">2022/09/12</span></h6>
---
## Amazon EC2
* EC2 is one of the most popular of AWS’ offering
* EC2 = Elastic Compute Cloud = Infrastructure as a Service
* It mainly consists in the capability of :
• Renting virtual machines (EC2)
• Storing data on virtual drives (EBS)
• Distributing load across machines (ELB)
• Scaling the services using an auto-scaling group (ASG)
* Knowing EC2 is fundamental to understand how the Cloud works
### EC2 sizing & configuration options
* Operating System (OS): Linux, Windows or Mac OS
* How much compute power & cores (CPU)
* How much random-access memory (RAM)
* How much storage space:
• Network-attached (EBS & EFS)
• hardware (EC2 Instance Store)
* Network card: speed of the card, Public IP address
* Firewall rules: security group
* Bootstrap script (configure at first launch): EC2 User Data
### Security Groups
* Security Groups are the fundamental of network security in AWS
* They control how traffic is allowed into or out of our EC2 Instances.
<center>

</center>
* Security groups only contain rules
* Security groups rules can reference by IP or by security group
* Security groups are acting as a “firewall” on EC2 instances
* They regulate:
• Access to Ports
• Authorised IP ranges – IPv4 and IPv6
• Control of inbound network (from other to the instance)
• Control of outbound network (from the instance to other)

### How to Create EC2 Instance:
#### The steps are explained in this [video](https://youtu.be/rjxWiX01iCQ).
1. Search for EC2 service in the top search bar.

2. Choose an instance from the left menu.

3. Click Launch instance Button.

4. Enter instance Name and choose the operating system you want, we usually use Amazon Linux or Ubuntu.

5. Chosse instance type (t2.micro For free tier). You can press Compare instance types to compare between different types.

6. As you can see $t2.micr$ has one vCPU, one GiB Memory and 0.0116 USD per Hour.

7. Click Create new key pair Or you can Proceed without a key pair (Not recommended).

8. Enter key pair name, chosse RSA and .pem the click create key pair.
<center>

</center>
9. Create security group or Select existing secutity group.

10. Configure storage. By default 8 GiB is mostly enough.

11. (optional) In Advanced details you can add User data. Specify user data to provide commands or a command script to run when you launch your instance.

12. Finally, in the summary, you can see a summary of the instance, specify the number of instances you want to create, and then click Launch instance.
<center>

</center>
13. Click view all instance.

### Connect to EC2 instance using the console (browser)
1. Select EC2 instance then Click connect form Action.

2. Then Click connect.

3. Now you are in the EC2 instance.

### How to SSH into your EC2 Instance
#### The steps are explained in this [video](https://youtu.be/CvnfQpdzDuE).
1. Open an SSH client.
2. Locate your private key file. (key.pem)
3. Run this command, if necessary, to ensure your key is not publicly viewable.
````linux
chmod 400 EC2_test_key.pem
````
4. Connect to your instance using its Public IPv4 address (in the Details):
````linux
ec2-54-234-126-10.compute-1.amazonaws.com
````

#### Example:
````linux
ssh -i .\test.pem ec2-user@34.238.240.140
````

### How to terminate or Stop EC2 Instances?

## Amazon Machine Images (AMIs)
* AMI are a customization of an EC2 instance
* You add your own software, configuration, operating system, monitoring…
• Faster boot / configuration time because all your software is pre-packaged
• AMI are built for a specific region (and can be copied across regions)
* You can launch EC2 instances from:
• A Public AMI: AWS provided
• Your own AMI: you make and maintain them yourself
• An AWS Marketplace AMI: an AMI someone else made (and potentially sells)
### AMI Process (from an EC2 instance)
* Start an EC2 instance and customize it
* Stop the instance (for data integrity)
* Build an AMI – this will also create EBS snapshots
* Launch instances from other AMIs
### How to create image form Ec2 instance?

### How to create EC2 from AMI
To help you get started, an AMI (AMI ID = 080ff70d8f5b80ba5) is provided with the following software:
* Python
* MySQL Server (root password ece1779pass)
* Database and AWS Flask examples covered in lectures
* gunicorn This is a high-performance server for Python-based applications. For an example of how to run it, look at the `run.sh` file inside /home/ubuntu/extras/run.sh
* In addition the directory in Desktop/ece1779 contains the following:
• databases: A PyCharm project with all examples from the databases lecture and tutorial
• extras: A PyCharm project with code for transcoding photos and a sample form that conforms to the load testing interface
<span style="color:#e20000" >**Note: Use ubuntu as user name when ssh.**</span>
````linux
ssh -i .\test.pem ubuntu@34.238.240.140
````

###### tags: `Parallel and Distributed Systems` `Cloud computing` `IUG` `Computer Engineering`
<center>End Of Lab 3</center>