AWS EC2 Instances basics
Tags: webdev, aws, cloud, devops
Published: 2023-12-28 23:37:08


When running performance tests locally, you may find that the hardware you are using is inferior. There are also other problems in the form of bandwidth or issues like the inability to use the local station for other purposes. Therefore, it is more stable to use cloud solutions such as aws ec2. How to create such an instance to be able to run tests on it?

## Creating an instance

To begin with, you need to go to [AWS](https://eu-west-2.console.aws.amazon.com/console/home?region=eu-west-2#) and properly register an account. After filling in all the data, we enter EC2 Instances.

![AWS ec2 Instance](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/z23gglz33alvplyfud4s.png)

The next step is to correctly create instances. To do this, we click the orange “Launch instances” button at the top. This will redirect us to a subpage where we can select the type of machine, its operating system and enter its advanced settings. In our case, it will be the ubuntu system, whose name is my-test-instance.

![AWS ec2 Instance 2](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/34uzavug1v7gg4bkb9zy.png)

It is important to create or select an existing key pair. Since we don’t have one, we create one from scratch. It is vital to select the correct key extension at the bottom (depending on what tool we will use to connect to the server).

![Image description 3](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/i8aqtovmzths5bcjo56c.png)

After generating the key and moving on, we get a message that our instance has been created.

![Image description 4](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/bxkrbh00jwozgwikmd61.png)

When we go to the list of instances again, a new record appears before our eyes. By clicking on it we get all the necessary information to connect to it.

![Image description 5](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/es9hm4ivat4ncvkskgtv.png)

By default, our instance is enabled. Remember to stop the machine when you are done by pressing Connect -> Stop.

## Connect to the Instance

We can connect to the created instance in two ways, depending on what type of key we generated in the previous step.

### SSH

The first way is a standard SSH session. To do this, open a terminal and execute the following command.

```
ssh -i KEYPAIR.pem PLATFORM@PUBLIC_DNS
```

In our case, it will be:

```
ssh -i my-test-keypair.pem ubuntu@ec2-18-132-63-123.eu-west-2.compute.amazonaws.com
```

### Putty

Another option is to use the Putty tool. It is simply a program that is a client for TELNET, SSH and rlogin services. Putty is used when the graphical interface is more understandable to us and we want to be able to save many session settings.

In order for the connection to Putty to take place, three data fields must be completed.

1. Host name (or IP address).

![Image description 6](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/3eaf03c6qgsvplnvtxkw.jpg)

2. User name.

![Image description 7](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/464luipe6ynh2gtc2hwz.jpg)

3. Private key file for authorization.

![Image description 8](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/4meve0iatjlsyn671cnu.jpg)

## Transferring files to an ec2 instance.

As in the previous case, the tool used will depend on the previously selected generated key pair.

### SCP

```
$ scp -i yourKey.pem C:\desinationPath ubuntu@publicDNS:/home/ubuntu/yourFileOrFolder
```

### Putty

```
$ pscp -i yourkey.ppk C:\desinationPath ubuntu@public_DNS:/home/ubuntu/yourFileOrFolder
```

## Downloading files from an ec2 instance.

Use the following syntax to download files or directory.

### SCP

```
$ scp -i yourKey.pem ubuntu@publicDNS:/home/ubuntu/yourFileOrFolder C:\desinationPath
```

### Putty

```
$ pscp -i yourKey.ppk ubuntu@publicDNS:/home/ubuntu/yourFileOrFolder C:\desinationPath
```