Serverless Framework

Serverless Framework

About

  • Serverless Framework is open-source software that builds, compiles, and packages code for serverless deployment and then deploys the package to the cloud.

  • It Helps us to focus on Business Logic Rather than software and Hardware

  • Developers write Lambda functions, which are triggered by the client app, and user’s requests come through the API Gateway. AWS Lambda provides functions as a service

  • We usually wrap up our serverless script in serverless.yml

Installation

  • Prerequisites:

    • Nodejs

    • AWS: To run serverless commands that interface with your AWS account, you will need to setup your AWS account credentials on your machine.

  • In Linux Follow the Below command to install serverless-framework

    npm install -g serverless
  • Verify Installation:

    serverless --version
  • The above command Will give you result similar to those below

    Framework Core: 2.20.1
    Plugin: 4.4.2
    SDK: 2.3.2
    Components: 3.5.1

Get Started with Serverless

An average serverless.yml will Look like the below

Create Project

You can Get started with the project by generating Templates

AWS-Python:

  • To generate AWS-Python Template for serverless , Use the below Command:

  • The Above Command will generate below mentioned two files in MyNewService Directory :

    • serverless.yml

    • handler.py

Similarly For JS ...

AWS-JS:

  • To generate AWS-NodeJS Template for serverless, Use the below Command:

  • The Above Command will generate below mentioned two files in MyNewService Directory :

    • serverless.yml

    • handler.js

To know more about other templates Click_Herearrow-up-right

Terms in-Detail:

Deploy a Service

So to deploy the service to AWS, use the below Command

Remove a Service

In order to remove a service that we've deployed, we can use Below Command

Key_Points

  • Permissions: If your lambda needs to access other AWS services (S3, SQS, SNS…), you will need to add the proper permissions via the provider>iamRoleStatements , To know more Click_herearrow-up-right

References

Last updated