This lesson is for PRO members.

Unlock this lesson NOW!
Already subscribed? sign in

Deploying a Node.js Application to AWS with Elastic Beanstalk

5:56 Node.js lesson by

In this lesson, you will take a sample Node.js and Express web application to Amazon Web Services by leveraging the managed service, Elastic Beanstalk. This lesson will cover packaging the application, configuring a new Elastic Beanstalk application, and deploying the packaged application to an environment within your application.

Get the Code Now
click to level up

egghead.io comment guidelines

Avatar
egghead.io

In this lesson, you will take a sample Node.js and Express web application to Amazon Web Services by leveraging the managed service, Elastic Beanstalk. This lesson will cover packaging the application, configuring a new Elastic Beanstalk application, and deploying the packaged application to an environment within your application.

Avatar
Igor

Thanks for the video, would be great to have video(s) that would show how to use S3, RDS, and other services with this node instance

In reply to egghead.io
Avatar
David

Absolutely! Be on the lookout for more content around this in the near future.

In reply to Igor

I have a basic Node.js application. This is using Express. It's basically just a "Hello World!" application. If you navigate to it, it's just going to show you some text. Let's go ahead and run that so we can see that in action.

I'm going to bounce over here to Firefox. You can see here that all this is doing is displaying some text. This is about as simple as you can get. Let's say you want to take this and deploy this to AWS. One of the ways we can do that is certainly with Elastic Beanstalk.

Let me go ahead and pull up Elastic Beanstalk. What I've done here is I've actually gone into the console and already navigated to Elastic Beanstalk. Once I'm here, you'll notice that in the top right, I have the option to create a new application. That's what we're going to do.

As it loads up, it's going to ask here for an application name. We'll use this sample EB application as our name. We'll have a sample Elastic Beanstalk application in for the description. This is going to go through the process now of beginning to create an Elastic Beanstalk application.

Now, there's two primary types of environments that you can have inside of Elastic Beanstalk. One is the web server and one is the worker. For this example, we're going to use the web server option. Once we go in here, it's going to ask a few questions.

One is the platform. Here, as I mentioned, we have a Node.js application, but you can see that Elastic Beanstalk supports a wide variety of different platforms. Let's go ahead and select Node.js. Then it's going to ask for the type of environment.

This is important, because it's going to affect the way that it actually creates the environment. For now, we're just going to focus on a single instance. That means that it's going to launch our Node.js application on one server. That's what we want for now.

The next thing we need to do here is we need to actually upload our application. You can use the sample application that they have. If you were to proceed through, it would launch that application, but I want to show you how to deploy the application that we were looking at earlier.

Let me migrate over here to finder. You notice here, this looks like a fairly standard Node.js application directory. In this case, we're going to grab both the package.json file and then we're going to add the app.js file.

What we're going to do here is we're going to go through the process of compressing this so we make a zip file. We'll call this "Sample Node App." This is what we'll actually use when we upload to Elastic Beanstalk. Let's go ahead and select upload your own. Let's browse to this.

You can see here we've got sample node app ready to go. Then we hit next. This will go through and upload this. The next thing we have to do is add in a few things about the environment. Let's talk just really quickly about environments.

Within Elastic Beanstalk, you have an application. Within that application, you can have multiple environments, so maybe production, staging, deployment. In this case, we're just going to call this one "Production."

Then we actually have to go in and change the name, because one of the things about this is this name has to be unique for every one that's using Elastic Beanstalk in that region. You can see here, we're in us-east-1. We want to change this to something. Let's call this...

Here we go, "Prod Sample App EB," for Elastic Beanstalk. Let's check availability. Perfect, that one's available. We could add a description here. We'll just call this "Production," and then we're ready to proceed.

Here it's going to ask about some additional resources. It's going to ask if we want to associate an RDS, which is the Relational Database Service from AWS, with the instance. We don't want to do that. It's going to ask if we want to associate it with VCP, which is a Virtual Private Cloud.

We don't need to deal with that yet either. We can just proceed past this. The next part here is where we need to add in a few additional configuration values. The first is the instance type. This is the type of servers that we're going to use to actually launch this.

I'm going to choose m3.medium, but you could just as well choose some of the micro instances because those are included in the free tier if you have a new AWS account. The next thing you need to do is select a key pair. This is critical.

If you ever want to SSH into this machine, then you need to be sure that you have configured an EC2 key pair. If you don't, and if you don't select one here, then you will never be able to SSH into those servers. You actually would have to go back, create a key, associate it, and then relaunch new instances with that key associated.

We can leave most of these other values at default. For example, I'm sure that we have enhanced health reporting, ensure that we're just using the default root volume type and size. Then let's hit next. The next thing you can do is configure environment tags.

These tags are just values that you can use to actually track your AWS resources. Maybe you have a hundred different EC2 instances and you want to distinguish which ones are production servers versus which ones are staging servers. In this case, we don't need to worry about it.

Then we have permissions, because we're not doing anything overly complex here, we can just accept the default values. It'll go through and create some default service roles for us and an instance profile for us. That's what we want.

With all of these things in place, we're now ready to actually launch our server. Let's just hit launch. Then it's going to start the process of actually creating this environment for us, and it'll go through the entire process of loading up all the necessary instances and then configuring them with our application.

Once the entire process is completed, we'll end up here on the dashboard. You can see that the health indicator says that it's OK. We can see that it's already taken a lot of steps to go through and launch, create the instance, and associate our application with it.

If I launch the application, just the URL that's provided here, on the dashboard, you can see that it's now running this Node.js application on AWS using Elastic Beanstalk. This application is now available for anyone to use.

HEY, QUICK QUESTION!
Joel's Head
Why are we asking?