How do I add an API Gateway trigger to a AWS Lambda function?
Tags: aws, programming, development, tutorial
Published: 2020-02-10 22:39:56

---
title: How do I add an API Gateway trigger to a AWS Lambda function?
published: true
cover_image: https://thepracticaldev.s3.amazonaws.com/i/tbkb21gfooovne4f10st.png
series: Learn AWS Lambda from scratch
canonical_url: https://tlakomy.com/add-api-gateway-to-lambda
tags: aws, programming, development, tutorial
---
## Before we start
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](https://egghead.io/s/km6vr) video collection I've published recently, check it out here: [Learn AWS Lambda from scratch](https://egghead.io/lessons/aws-wtf-is-aws-lambda?pl=learn-aws-lambda-from-scratch-d29d?af=6p5abz).

---

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](https://dev-to-uploads.s3.amazonaws.com/i/wswwy1kgi1o965aw5dwl.png)

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

![AWS Lambda trigger menu](https://dev-to-uploads.s3.amazonaws.com/i/l46nclle8f4f11361zuy.png)

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](https://dev-to-uploads.s3.amazonaws.com/i/89qnfoob19dbn6lguvxx.png)
<figcaption>HTTP API and REST API are the most googleable names *EVER*</figcaption>

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](https://dev-to-uploads.s3.amazonaws.com/i/fhfm5xcqsh4eqdhwanak.png)

(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!)

---

I hope you've learned something interesting - in the next post we're going to learn how to add logs to AWS Lambda function and review them in AWS CloudWatch 🌟

Or you can check the video series [here](https://egghead.io/lessons/aws-wtf-is-aws-lambda?pl=learn-aws-lambda-from-scratch-d29d?af=6p5abz) and feel free to reach out to me on [Twitter](https://twitter.com/tlakomy)!