Setting Up AWS EC2 Instance for Beginners

Setting Up AWS EC2 Instance for BeginnersChristopher BuiBlockedUnblockFollowFollowingJan 13If you are working on a big data machine learning project, most likely you require the services of Amazon Web Services (AWS), Google Cloud Services, or Microsoft Azure.

My first exposure to cloud based computing was with AWS, so that is the platform I am most familiar with.

I wish the process of setting up a virtual environment with the correct operating system and packages was as easy as clicking on an option, but for security reasons and an offering of a wide availability of options, that is not the case.

Instances vary by storage capacity, along with CPU and GPU capabilities.

Amazon details their options here.

Note: If you select a relatively powerful instance, then AWS requires you to send in an explanation of your usage intentions.

They usually reply within a couple days.

Change Your .

pem Key PermissionsAfter selecting your instance, you are asked to create a new or choose an existing key pair as shown below.

Your key will be downloaded to your computer as a .

pem file.

It is best practice to carefully store and organize your keys.

If you lose them, then there is absolutely no hope in your ability to access your EC2 instance again.

Please read the prior sentence 10 times.

Launch your instance.

I usually store my key in the hidden folder labeled .

ssh on MacOS.

Assuming your key was downloaded to the downloads folder, open a Terminal window and type the following commands with your appropriate key name:cd downloadsmv ~/downloads/yourkey.

pem ~/.

sshYour key by default comes with permission restrictions that will prevent you from either accessing your instance or using other commands on it.

To avoid that issue, and assuming you are in directory that your key is located, type the following:chmod 700 yourkey.

pemAccess Your EC2 Instance via SSHEC2 instance, check; .

pem key, check.

Before proceeding, you need to locate your public DNS highlighted in green.

Click on your newly created instance and a description box should appear like the own below.

You use the ssh (secure shell) command to access your instance.

Open a Terminal window and type the following, obviously substituting your own key name and public DNS.

ssh -i ~/.

ssh/yourkey.

pem ubuntu@ec2-xx-xx-xxx-xxx.

us-west-2.

compute.

amazonaws.

comThe Terminal window should show a prompt welcoming you to the instance’s virtual environment.

From this window, you can transfer your files and work on your awesome projects!Note: Depending on your AMI’s operating system, you will type “ec2-user” (usually for base Linux), “ubuntu”, or your appropriate OS title before the “@your_public_DNS” in the ssh command above.

BIG NOTE: Your public DNS may change depending on your location.

So if you have trouble accessing your instance, then more than likely your public DNS has changed, in which case, reconfirm your correct public DNS.

Open a new Terminal window that its current directory is located on your computer and not in the instance environment, and type the following, obviously substituting your own key name and public DNS.

Upload a File From Computer to Instancescp ~/.

ssh/yourkey.

pem ~/path/to/file ec2-user@ec2-xx-xx-xxx-xxx.

compute-1.

amazonaws.

com:path/to/fileDownload a File From Instance to Computerscp ~/.

ssh/yourkey.

pem ec2-user@ec2-xx-xx-xxx-xxx.

compute-1.

amazonaws.

com:path/to/file ~/path/on/local/machineAmazingly, in the Terminal window that has accessed your EC2 instance, you can use Git commands to pull and push files between your instance environment and your Github, as you would normally on your local machine.

All data on the instance is stored on AWS’s servers obviously.

REALLY IMPORTANT NOTE:AWS charges you a timely rate relative to the instance specifications you chose.

Whether you are doing light or heavy work, if your instance is turned on, AWS will charge you.

I, and a few of my colleagues, made the rookie mistake out of ignorance and negligence of not understanding the protocol described above, resulting in our accumulating bills of several hundred dollars.

Luckily Amazon was empathetic and rescinded the charge.

However, you should not let this situation happen.

Hence, whenever you are finished with a working session, 1 minute or 1 hour, always stop your instance.

Then simply start it when you resume work.

Terminating will delete your entire instance, so you must create a new one from scratch.

And that’s a wrap!.I had a harrowing experience with setting up AWS when I started out, but hopefully this guide can be your little cheat sheet.

Sometimes, the material that we learn is not what is difficult, but our learning methods and resources are what contributes to the challenge.