Invoke API running from AWS Lambda with NodeJS
A young team member asked me how we can use lambda to run a certain logic every time a certain endpoint gets hit with an HTTP request.
I thought it was pretty simple but after going through the steps I realized that the AWS interface is not that straightforward and could be confusing.
The following is a simple step-by-step guide that explains how to create such a lambda.
1. Go to lambda tab
2. Implement your logic
3. when your code is ready, click on “create a function”
4. give it a name and click “create a function”:
5. Give a name to the new-role that you want to execute it, and click on “create a function”
6. Click on “API gateway” and go to the dropdown marked as #3 in the screenshot (you can always return to it by clicking on #2 — in case you lost it)
7. choose “create a new API” and choose security “open”. then click on “add”
8. don’t forget to hit “save”
9. Now you’ll see a new URL which you can paste in your browser (or use cURL etc), once this url is called — your code will get triggered
10. This is just a demo, if you want to create a _real_ endpoint you should look further into making it secure (i.e. not “open”)
Good luck!