'How to create a nodejs AWS lambda function locally using vscode and not serverless or SAM CLI?
I've go through hundreds of blogs/videos/resources but nowhere it mentions how to create a simple lambda function for Nodejs REST API locally using vscode, AWS toolkit extension and AWS cli. Is there any way where I can create a simple nodejs endpoint on my local and run using above and not serverless or SAM?( There's some internal restrictions hence I can't use them)
Solution 1:[1]
What you need is to set up a API gateway and event trigger for your lambda that triggers whenever a HTTP request comes in. So here are steps
- Look into serverless framwork where you will define a serverless.yaml file that will have configuration to mention how your lambda will get invoked (In this case, its a HTTP event)
- In your IDE of choice, use serverless-offline npm package
- Your IDE config will look something like this (This example uses IntelliJ IDE) IDE config to start up Lambda in local
- Once you start up the service in local, you should be able to hit the REST endpoint in local using any rest client like Postman
- Instead of (4) above you could also directly invoke your lambda function in local using AWS CLI like
aws lambda invoke /dev/null \ --endpoint-url http://localhost:3002 \ --function-name <Your lambda function name> \ --payload '{<Your payload>}'
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | Ajit R |
