Let’s face it — AWS is a convoluted web of so many services and can be really difficult to wrap one’s head around. That’s certainly how I felt, the
first time I deployed a Node.js app to the service. PSA I love Clis but definitely not a fan of the Elastic Beanstalk Cli.
Compared to Heroku or DigitalOcean, AWS Elastic Beanstalk(ikr Such an interesting name!) can be a little difficult to wrap your head around but it’s probably one of the easiest AWS services to use. Elastic Beanstalk is a similar service to Heroku and DigitalOcean i.e it provisions a server for you
without you having to do any of the complex DevOps work yourself.
Prerequisites
Let’s get started!
First things, first, you need an AWS account. It’s pretty complex to setup. I would advice you follow freecodecamp’s AWS Cloud Certified Associate video on setting up an AWS account.
You’d get a screen like below once it’s done.
1. Your node app should be setup and already running perfectly on
localhost. My app holds a list of blogs and is an app I’m building
following the fullstack course at fullstackopen.com.
I'm using MongoDB Atlas for my database. Another thing to remember is that for your ports, you need to have them set up as
const PORT = process.env.PORT || 3001
This ensures that whatever port is being used by the server AWS gives us, is picked up by our App.
2. In your AWS console, click on Services(see the menu) > Code pipeline. We will be hooking up our GitHub to AWS so that each time we push updates, our App is automatically deployed to AWS.
3. Click Create Pipeline. Fill in the pipeline name. The role name gets filled out automatically. Then select new service role as your service role. Click next.
4. Select GitHub as source provider. Click connect to GitHub to hook up your GitHub account to AWS. Select the repo your code is in and the branch. Skip the build stage and confirm.
5. Enter your application name that you created in the Elastic Beanstalk
console and select the environment name(automatically generated from
your app name) from the list.
6. Click next > Create pipeline.
7. And that’s it. We wait for our App to deploy. Hopefully you get green screens like below.
8. If anything goes wrong, you can check the environment logs.
9. To view your Node.js application: Services > Elastic Beanstalk > Click on the App’s name under environment name. The link will be displayed under the App’s name. In my case under NodejsBlog-env. (See Image in Point 4 of the 1st section)
10. You can preview my app here.
Side Notes
There were certain issues I encountered along the way.