Serverless applications brought about a new paradigm in programming.
You no longer need to worry about server infrastructure and concentrate only on your business logic.
AWS lambda serves this purpose.
And Serverless is a framework that eases the development and deployment of AWS lambdas.
Here is how to set up the serverless framework in your development machine to get started:
STEP 1:Install Node.js and npm
The AWS Serverless Framework is built on Node.js, so you will need to have it installed on your machine. You can download the latest version of Node.js from the official website (https://nodejs.org/) and follow the instructions to install it. npm, which stands for Node Package Manager, will also be installed with Node.js.
STEP 2: Install the AWS Serverless Framework:
Open a terminal or command prompt and enter the following command:
npm install -g serverless
This will install the AWS Serverless Framework globally on your machine.
STEP 3: Configure your AWS credentials:
Serverless should know which AWS account to deploy your app to.
For this , you will need to configure your AWS credentials. You can do this by creating an AWS IAM user with the necessary permissions and then creating a file named “credentials” in the
[USER_HOME_DIRECTOR]/.aws/ directory on your machine where USER_HOME_DIRECTORY is the path of the home directory in your machine. It is C:/Users/hp in my machine. The contents of the file should look like this:
aws_access_key_id = YOUR_ACCESS_KEY aws_secret_access_key = YOUR_SECRET_KEY
YOUR_SECRET_KEY with your actual AWS access key and secret key, respectively.
STEP 4: Create a new serverless application:
To create a new serverless application, use the serverless command in your command prompt/terminal:
This will ask you a few prompts as what type of application you need:
You can choose the appropriate one.
Alternatively you can also specify the template in the command:
This will create a new Node.js-based serverless application in the current directory.
STEP 5: Deploy your application:
To deploy your application to AWS, navigate to the root directory of your application and enter the following command:
This will package and deploy your application to AWS.