How to Setup Serverless Framework

How to Setup Serverless Framework

What is serverless?

Serverless is a Framework. The Serverless Framework pioneered serverless architecture on AWS, a transformative approach to building applications on cloud infrastructure that auto-scales, incurs no charges when idle, and typically demands minimal maintenance. Today, it continues to be the leading developer tool for deploying serverless architectures.

Serverless is AWS Technology Partner.

Refer this documentation for more details: https://www.serverless.com/framework/docs

Setup serverless account

  • Signup/Login into the Serverless

  • After login, you will see such screen:

Install Node.js

To run serverless we need to install it in our machine. As serverless works on Node.js we need to install it first.

For Ubuntu machine run below command to install Node.js version 18 and npm:

sudo apt-get update && curl -sL https://deb.nodesource.com/setup_18.x | sudo bash - && sudo apt-get install -y nodejs && node --version && npm --version

I am going to launch an EC2 instance and in that I will intall everything. [You can use your local machine for the same]

Connect to the instance, install Node.js and then install npm. You may need to reboot your system.

Install Serverless

Now, To install serverless framework run command:

sudo npm install -g serverless

npm(node package manager) will install serverless globally(-g).

Install and configure AWS CLI

Next, install AWS cli. This will help serverless to communicate with AWS.

sudo apt-get install -y awscli

You also need to configure it. If you don’t then serverless will ask you while creating a project.

You can find steps here: https://neel-soni.hashnode.dev/iam-programmatic-access-and-aws-cli [In the permissions, give admin access and that will be fine.]

Here, I created a user with admin acess.

aws configure

Enter AWS Access Key ID and AWS Secret Access Key.

Serverless Log in CLI

Login to your serverless account with cli in order to deploy the applications, use command:

serverless login

Serverless project

If you have exitsting project with serverless.yml file then run command:

serverless deploy

The above command will start creating the project on AWS.

If you don’t have any, then enter below command to start a new project.

serverless --org=<your-organization-name>

<your-organization-name> will be your organization name. You can find out in serverless website settings.

Next, It will give you options to which type of project you want to create and then follow the given instructions by serverless.

Done!

You have completely setup the serverless and AWS. After deploy command your project will be deployed and will create services on AWS automatically.