Arnab Ghosh
Arnab Ghosh

Arnab Ghosh

Step-by-Step Guide To Run Your First Serverless Express.js App on AWS Amplify

Step-by-Step Guide To Run Your First Serverless Express.js App on AWS Amplify

This guide will help you to deploy your express.js serverless app on AWS Amplify.

Arnab Ghosh's photo
Arnab Ghosh
·Sep 11, 2022·

5 min read

Subscribe to my newsletter and never miss my upcoming articles

Play this article

Table of contents

The month of September is extra special for me this year.

I built my first full-stack project and deployed it using Netlify and AWS Amplify serverless function.

The cherry on top, I also got it ranked #11th for the day on ProductHunt.

pomo.do

In this blog, I'll help you to deploy your first projects on AWS Amplify as well:

At the end of the tutorial, you'll be able to run a simple serverless express.js app on AWS Amplify.

Prerequisites

However, to move forward with this tutorial, you need to have the following:

  • Node and npm installed on your computer,
  • A new AWS account,
  • Basic knowledge of Node.js and Express.js

Step by Step Guide To Run Express.JS App on AWS Amplify:

Here is a step-by-step guide to deploying a serverless express.js app on AWS amplify.

Step 1: Install Amplify CLI in your System

  • Open a terminal on your computer and type the following code:
sudo npm install -g @aws-amplify/cli
  • Give admin access in your windows system/ If you have a Mac, then type your password and hit enter. It will install the Amplify CLI on your computer.

Step 2: Configure Amplify CLI

  • Open the terminal on your computer and type the following code:
amplify configure
  • It will open up the AWS console.

  • Once you logged in to the console with your root user, jump back to the command line.

  • Next, it will ask you to Specify an AWS Region. You should specify the region where you live in.

Specify AWS Region.

  • Then, give a username in your IAM account, and click enter.

give a username in your IAM account

  • After that, it will open the IAM dashboard in your AWS account.

  • Don't change anything here. Keep on clicking next till it asks you to Create User. Click on it.

  • Next, you'll be given an access code, and a secret key

AWS amplify access code and secret key

  • Copy the access code and jump back to the command line, and paste the access key id. Do the same for the secret key.

  • Then, it will ask you to create a profile name on your local machine. Give any profile name.

create a profile name on your local machine

  • With that, AWS amplify is configured, and you are ready to create any project in AWS amplify.

Step 2: Initialize a New Amplify Project

  • Initialize a new amplify project by running the following code in the terminal:

    amplify init
    
  • Then, give the name of the project and then confirm the configuration.

Initialize a New Amplify Project

  • After that, it will ask you to select the profile on which you want to create the app. Select the profile you just created. And it will configure the development environment for you.

configure AWS Amplify development environment

Step 3: Add an Amplify Serverless Express.js API

  • To create an API, type amplify add api on the command line.

  • Choose the type of API you want to create. Here, we are creating a REST API, so choose REST.

Screen Shot 2022-09-11 at 6.11.07 PM.png

  • Provide a name to the resource.

Screen Shot 2022-09-11 at 6.12.04 PM.png

  • Provide a path name for the API endpoint

a path name for API endpoint

  • Choose a name for the AWS lambda function and then choose the runtime environment. For this tutorial, we're gonna choose node.js.

choose the runtime environment

  • Now, select the serverless express.js function option to create a pre-configured express.js app.

serverless express.js function

  • Next, it may ask you to configure advanced settings. For now, choose "No."

configure advanced settings

  • Next, if you want to modify anything in the server code, choose 'Yes' to edit the local lambda functions now. Go to /amplify/backend/function/<function name>/src. In this directory, the express.js app is located. You can modify the express.js app the way you want. For now, I'm going to keep it as default.

edit the local lambda functions

  • After you're done editing, click enter to continue in the command line. Click no when it asks to restrict API access.

restrict API access

Step 4: Deploy the Serverless Amplify API on AWS

  • After you're done with creating the Express.js app, jump on the command line, and type amplify push to finally deploy the app on AWS.

Deploy serverless app to AWS

  • Here's the REST API endpoint. Open it on a browser, and go to the path you've created earlier to check if the API is working:

Test REST API endpoint

  • Voila! You've successfully deployed your first serverless application on AWS amplify.

Test REST API endpoint in browser

Conclusion

I hope this guide simplifies the process of creating a serverless express.js app for you.

If you need further help, you can connect with me on LinkedIn and Twitter

Go to my Portfolio

Resource: AWS Amplify Docs

Read my other blogs:

Did you find this article valuable?

Support Arnab Ghosh by becoming a sponsor. Any amount is appreciated!

See recent sponsors Learn more about Hashnode Sponsors
 
Share this