This site runs best with JavaScript enabled.

AWS Made Simple: Trigger a lambda function via API Gateway

Tomasz Łakomy

May 27, 2020


Once we create an AWS Lambda function we probably want to be able to call it (otherwise, why bother creating a function at all?).

As we established in the previous posts, an AWS Lambda function can be triggered by various events - including an HTTP request, which [citation needed] is probably the most common use case.

With AWS Lambda you can create a serverless REST API in no time!

Let's start with a brand new lambda function, which as you can see - by default has no triggers.

A brand new AWS Lambda function in AWS Console

Consider clicking on the Add trigger button, who knows what will happen!

AWS Lambda trigger menu

As we can see, there's a surprising number of things that can trigger a lambda function. Maybe one day we'll be able to trigger lambda by just thinking about it, who knows.

In any case - let's select API Gateway from the list and let's create an API from scratch:

API Gateway creation screen

HTTP API and REST API are the most googleable names *EVER*

We can choose between HTTP API and REST API. HTTP API is still in beta but it's cutting edge and we want to one of the cool kids - let's go with that.

Leave everything as default and click on Add.

(Quick note: by default the newly created API will be open, so we'll be able to access it from the Internet. Not a huge deal now, but we might consider being more careful once our lambda functions deal with sensitive data etc.)

Lo and behold! We have created an API Gateway and connected it to our Lambda function

API Gateway trigger connected to AWS Lambda

(Consider adding this skill to your LinkedIn, more than happy to endorse you)

Our brand new API endpoint will look more or less like this:

https://RANDOM_STUFF.execute-api.eu-central-1.amazonaws.com/default/MY_FUNCTION_NAME

And once we paste it into our browser, something magical will happen - a "Hello from Lambda!" string will appear on our screen 🎉

This is fantastic - now we're able to create our own APIs in no time, and the whole process takes minutes (if not seconds!)

Óne more thing!

If you don't feel like reading and prefer to watch a bunch of quick (less than 3 minutes) videos - this blog series is based on a 💰free 💰egghead.io video collection I've published recently, check it out here: Learn AWS Lambda from scratch.

AWS Cloud Development Kit egghead.io course logo

I've also launched an AWS Cloud Development Kit course on egghead.io - make sure to check out Build an App with the AWS Cloud Development Kit!

AWS Cloud Development Kit allows you to build the entire stack (frontend, serverless backend, AWS infrastructure) using a single programming language - TypeScript!

🔥🔥🔥

Share articleBuy Me A Beer

Join the Newsletter



Tomasz Łakomy © 2022
Cloudash - serverless monitoring. Simplified