Invoke API running from AWS Lambda with NodeJS

Someone asked me how can we use a lambda in order to run a certain logic every time that a certain endpoint gets hit with a HTTP request.

I thought it’s pretty simple but after starting to go through the steps I realized that 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!