Steps to set up AWS Lambda local development environment [Serverless Framework Edition]
I’ll introduce the steps to set up a local development environment for AWS Lambda with Serverless Framework.
npm install --save-dev serverless-offline
serverless.yml
plugins:
- serverless-offline
functions:
test:
handler: handler.index
events:
- http:
path: testpath
method: get
With the above configuration, you can start the project with the serverless offline start command.
$ serverless offline start
Serverless: Starting Offline: undefined/undefined.
Serverless: Routes for crawling:
Serverless: GET /testpath
Serverless: (none)
Serverless: Offline listening on http://localhost:3000
curl http://localhost:3000/testpath
By accessing it like this, you can execute handler.index.
npm install --save-dev serverless-offline-scheduler
serverless.yml
plugins:
- serverless-offline
- serverless-offline-scheduler
functions:
test:
handler: handler.index
events:
- schedule: rate(1 minutes)
With the above configuration, events:schedule can be checked in cron format with the serverless schedule command.
$ serverless schedule
Serverless: scheduler: scheduling test/handler with */1 * * * *
Also, it can be executed with the serverless offline start command.
$ serverless offline start
Serverless: scheduler: scheduling test/handler with */1 * * * *
Serverless: Starting Offline: undefined/undefined.
Serverless: Routes for index:
Serverless: (none)
Serverless: Offline listening on http://localhost:3000
Serverless: scheduler: running scheduled job: test
npm install --save-dev serverless-dynamodb-local
serverless.yml
plugins:
- serverless-dynamodb-local
- serverless-offline
- serverless-offline-scheduler
custom:
dynamodb:
start:
port: 8000
When using serverless-offline, you can also start serverless-dynamodb-local with the serverless offline start command.
serverless offline start
If you want to start only DynamoDB Local, you can start it with the serverless dynamodb start command.
$ serverless dynamodb start
Dynamodb Local Started, Visit: http://localhost:8000/shell
By accessing http://localhost:8000/shell/, you can operate the DynamoDB JavaScript Shell from your browser.
That’s all from the Gemba where we want to set up a local development environment for AWS Lambda with Serverless Framework.