Search icon CANCEL
Subscription
0
Cart icon
Your Cart (0 item)
Close icon
You have no products in your basket yet
Arrow left icon
Explore Products
Best Sellers
New Releases
Books
Videos
Audiobooks
Learning Hub
Free Learning
Arrow right icon
Arrow up icon
GO TO TOP
AWS Lambda Quick Start Guide

You're reading from   AWS Lambda Quick Start Guide Learn how to build and deploy serverless applications on AWS

Arrow left icon
Product type Paperback
Published in Jun 2018
Publisher Packt
ISBN-13 9781789340198
Length 184 pages
Edition 1st Edition
Languages
Tools
Concepts
Arrow right icon
Author (1):
Arrow left icon
Markus Klems Markus Klems
Author Profile Icon Markus Klems
Markus Klems
Arrow right icon
View More author details
Toc

AWS API Gateway

In the previous section, we created our first Lambda function. Now let's explore the API Gateway Service. Let's take a look at the API Gateway Service web dashboard. We will use it to create a new API and then connect that API to our Lambda function. Last but not least, we will test our API, and through our API, we will invoke the Lambda function. So let's start.

Log in to the Management Console in the Frankfurt region where you can create your first Lambda function. Now let's go to the API Gateway Service. If you don't have an API gateway, click on Let's Get Started. Amazon might ask you to import an API. Import it, and once done, you will be able to see a reference API that can be used to learn more about APIs, but it will be a bit too complex for our first use case. So, let's create a simpler API by clicking on the Create API button. Create a new API and give it the name FirstAPI. After that, click on Create API.

So now I have an API, and it can configure a couple of things, but for now, let's just create a resource that can be found in the Actions button, as shown in the following screenshot:

I will take a REST resource and name it foo. It will get the resource path foo. After this, I will click on Create Resource. A resource alone is not enough; I also need a method. So let's click on Create method and select an HTTP GET method, as seen in the following screenshot:

Click on the little checkmark. Et voila! We have a simple API with one resource, foo, and a GET method:

Now we can integrate it with different kinds of services. We want to integrate it with our Lambda function, so the first radio button is correct. We select the region. In our current example, we are in the Frankfurt region and our Lambda function is also in the Frankfurt region, so select eu-central-1, which is the Frankfurt region, and then type in the Lambda function name. I gave it the name firstLambda. Click on Save.

Now the API gateway will ask you if you give the API gateway permission to invoke your Lambda function:

So remember from the beginning that you need to give your API permission to invoke your Lambda function; otherwise, just anyone can invoke your Lambda function, which you don't want. Click on OK.

Now, we have created an integration between our API and our Lambda function. Let's click on the little Test button, as shown in the following screenshot:

Once you click it, you will be able to execute an HTTP GET request by scrolling down the page and clicking on the TEST button.

Within 90 milliseconds, we will get a response back—Hello from Lambda, as seen in the following screenshot:

So it looks like we really invoked our Lambda function, but can we be sure? Let's check. Go back, and click on the foo resource and then click on the GET method. Now we can see our integration again, and on the right-hand side, you can see the Lambda function that I have integrated my API with. Click on it and you will be directed to the Lambda dashboard with your Lambda function. Let's take a look at the Monitoring tab:

As you can see, it has in fact just been invoked—a couple of times, actually.

lock icon The rest of the chapter is locked
Register for a free Packt account to unlock a world of extra content!
A free Packt account unlocks extra newsletters, articles, discounted offers, and much more. Start advancing your knowledge today.
Unlock this book and the full library FREE for 7 days
Get unlimited access to 7000+ expert-authored eBooks and videos courses covering every tech area you can think of
Renews at $19.99/month. Cancel anytime
Banner background image