Before you start you will need to have
You can refer this blog if you are not familiar with the basics of serverless
We will create a project folder and initialize an npm project. Create a new serverless service in the project folder.
mkdir my-serverless-project
cd my-serverless-project
npm init -y
serverless create --template aws-nodejs
The Serverless framework generates a boilerplate for the application. Out of these, handler.js
and serverless.yml
are significant.
Now we will install [serverless-offline](https://www.npmjs.com/package/serverless-offline)
which is a plugin used to run the Serverless framework on the localhost. This will emulate the Lambda and API Gateway on our local machine to speed up your development cycles. Otherwise, we will have to deploy the service to AWS every time to test a change.
npm install -D serverless-offline
Modify the serverless.yml
file to include the plugin.
service:
name: serverless
plugins:
- serverless-offline
provider:
name: aws
runtime: nodejs12.x
apiGateway:
minimumCompressionSize: 1024
environment:
AWS_NODEJS_CONNECTION_REUSE_ENABLED: 1
functions:
hello:
handler: handler.hello
events:
- http:
method: get
path: /
#coding #programming #serverless #aws #aws-lambda