MLDeploy and Connect an Amazon EC2 Instance for Cloud Computing with Amazon Web Services

Set up a cloud environment and train a model on GPUs for $0.90

Cloud computing is very much a buzzword in the machine learning community, but what does it really mean?

It turns out, cloud computing can be a real lifesaver for your machine learning needs, and it doesn’t need to break the bank.

In this tutorial, you’ll learn how to quickly set up an Amazon EC2 instance for under a dollar and connect to it via SSH.

Now, if none of that made sense, don’t sweat it. This tutorial is intended for beginners, so you don’t need to know anything about Amazon Web Services to follow along.

By the end, you’ll have a computer running in the cloud, which you can connect to and use for almost anything!

The Basics

Before we dive into AWS, let’s learn some of the basics. In almost all machine learning topics, it’s easy to get overwhelmed by all of the abbreviations and acronyms, so let’s clarify all of those.

Amazon Web Services (AWS)

If you’ve been in the machine learning or web development community, you’ve likely heard of Amazon Web Services.

In case you aren’t familiar, it’s an Amazon-run platform that provides cloud services (such as model training and web hosting) on a pay-as-you-go basis.

Just visiting their website can be daunting, as they offer thousands of different options and services!

Elastic Compute Cloud (EC2)

What we’ll be using in this tutorial is Amazon’s EC2. This is a sub-service under the Amazon Web Services umbrella that offers computing power in the cloud. Essentially, EC2 allows you to “rent” and connect to a computer in one of their server farms via the Linux command line.

Secure Shell (SSH)

Last term here: Secure Shell. If you’ve worked with devices such as the Raspberry Pi or have done networking of any kind, you’ve likely heard of SSH.

If not, SSH allows you to form a secure connection with the client device (in this case, your EC2 instance) through your command line. This is convenient because it doesn’t require your network to be secured, but it guarantees a secure connection.

Getting Started

Since Amazon has a finite number of computers to offer, they don’t allow users to start creating and using instances right away.

Instead, you need to create an account, wait, and then request instances. We’ll walk through all of that, so don’t fret!

Create an Account

To start off, you’ll need to create an account. If you already have one, you can log in and skip to the next step. If not, head to the login page and create an account there.

If you don’t have an account, use the Create a New AWS Account button to create a new account. You’ll need to enter your login credentials and an account name (sort of like a username).

Once you’ve entered the appropriate information, tap Continue and follow the rest of the prompts — they’re pretty straightforward. You’ll be asked to enter your address and billing details so they can charge you for what you use.

Select Region

If everything goes well, you’ll end up inside your AWS Management Console, where you’ll be able to perform a variety of different tasks. Here’s how my console looks:

Before you start, though, you’ll need to select your region. Amazon assigns you your instances based on the region you’ve indicated, since they have quotas per region. Most people select the one closest to them.

Later, if you’re not getting the instances you requested, you can change your region to somewhere else.

If you’re running an enterprise-level app on AWS, then it makes sense to research which region you’ll be choosing, as some governments have different regulatory guidelines for servers running in their countries.

Starting your Virtual Machine

By now, you should be all setup and ready-to-go with your new AWS account. You’re finally ready to launch the long-coveted virtual machine instance.

Let’s shift gears from the account creation part and focus on the actual instances and how to set them up.

Launching an Instance

In your AWS Management Console, click the Launch a Virtual Machine button under the Build a Solution heading.

Often, if you have a new account, you’ll have to wait for Amazon to review it, and you’ll get a screen like below. Luckily, though, it only takes about a day for that to happen until you’re back on your way. If this happens to you, simply wait for your account to activate and then return to this tutorial.

Once you’re up and running with the account, you’ll see the following screen:

This is where you’ll be able to launch and manage all of your instances. In fact, you’ll never need to return to the AWS Management Console if you’re only using EC2 instances, so might as well bookmark this one.

Choosing an AMI

An Amazon Machine Image, or AMI, tells your instance how to run, and it specifies parameters such as the operating system to run with.

We’ll be sticking with the defaults for the purposes of this tutorial, but if you’d like you can learn more about how to choose AMIs. Click the orange Launch Instance button on your EC2 Console to begin.

In this case, I’ll be choosing the Amazon Linux 2 AMI, which will create a standard, Linux-based virtual machine. When you’re using AWS for a real-world application, however, I highly recommend researching the AMI before using it.

Choosing an Instance Type

After you’ve selected your AMI, you’re ready to choose the actual instance type. The only one available with your free trial is the t2.micro instance type; however, if you want to train any real machine learning models, you’ll need to go with something more robust, such as the p2.xlarge instance.

For now, leave the default one, since you’ll need to request customer support for an upgrade in order to use anything else.

Then, click Review and Launch to launch your instance.

And, finally click Launch. For the amount of time you run it, this instance will be essentially free. If you choose to use the p2.xlarge instance, you’ll only be running at $0.90/hour.

This is a pretty affordable price for an NVIDIA Tesla K80 GPU, so if you need it, go for it! Check out the other instances to learn more about what each of them can do.

Connecting to Your Instance

Last but not least, you’re ready to use SSH to connect to your instance via your computer’s command line.

This step allows you to later send commands to your instance and use it as if it’s your own computer (which it is, in a way).

Create a Key Pair

In order to guarantee a secure connection, SSH needs some way to verify that you’re the person who should be connecting to the instance.

To verify this, you’ll need to download a Key Pair, which you’ll use to authenticate your connection to the instance.

To generate this, select Create a New Key Pair from the dropdown and give it a name. Then, click Download Key Pair, and wait for it to appear in your downloads folder.

After that, click on Launch Instances to finally get everything up and running. If you launch without creating a Key Pair, you’ll have no way of connecting to your instance. At the end, you’ll get this confirmation screen:

Then, click View Instances to see your dashboard. This will show you all of your running instances and give you options to connect with them.

Using SSH

The last step is finally here: all that’s left to do is connect with your instance using the command line on your computer. In most operating systems, you can simply open a Terminal window. In the dashboard, select your instance, and click Connect.

This should bring up a popup with a few commands:

Make sure that a standalone SSH client is selected under Connection Method. Using your command line, enter into your Downloads folder using cd or an equivalent command. Then type the line starting with chmod whose form looks like the following:

Then, paste in the line starting with ssh afterwards:

Make sure you only use what’s in your dashboard, since those contain the correct IP addresses and names to log into your instance. Once you do this, you’ll be asked to verify that you want to connect, so type yes after the prompt. Lastly, you’ll need to update your instance, so type the following:

This will make sure that everything is updated and ready for use!

Conclusion

That’s it! You have an Amazon EC2 instance up-and-running! You can now treat this instance as you would any other computer—train machine learning models on it, run scripts, or whatever else you can think up. Just make sure you read up on all of the links provided throughout this tutorial before you use these instances for real-world applications; they may save you a lot of time, hassle, and money in the long run.

If you were able to run a p2.xlarge instance, you saw that for only $0.90/hour, you could get access to a modestly powerful GPU for your model training tasks and possibly more, depending on your needs. Great work!

Be sure to smash that “clap” button as many times as you can, share this tutorial on social media, and follow me on Twitter.

Avatar photo

Fritz

Our team has been at the forefront of Artificial Intelligence and Machine Learning research for more than 15 years and we're using our collective intelligence to help others learn, understand and grow using these new technologies in ethical and sustainable ways.

Comments 0 Responses

Leave a Reply

Your email address will not be published. Required fields are marked *