API Gateway#
Your Lambda function works, but it can only be invoked from the AWS CLI or AWS Console. To make it accessible over HTTP (so you can call it from a browser, mobile app, or any HTTP client), we need Amazon API Gateway.
What Is API Gateway?#
API Gateway is a managed service that creates, publishes, and manages APIs. It sits in front of your Lambda function and handles much of what a web server or proxy would do. Have a look at this diagram:

Another critical concept: we can connect multiple Lambda functions to the same API Gateway. This lets us hook up arbitrary Lambda functions into a single application. It can be a wonderful convenience, or indecipherable spaghetti.
When you make an HTTP request through API Gateway, it captures your actual IP address and includes it in the event it sends to Lambda. Unlike CLI and AWS Console tests where you provide mock data, this is a real HTTP request traveling over the internet, so you’ll see your real IP in the response!
I love prototype-driven development; it’s a powerful tool to build a toy version of the app or feature you’re thinking about to see what it would take to deploy it in production. API gateways and lambdas can be a great way to get your proof of concept online.
Assignment#
Create an API Gateway HTTP API named patientping-ip-api that exposes your Lambda function over HTTP. (Optional: repeat with the CLI.)
Cost check: API Gateway charges for HTTP requests and data transfer (pay-as-you-go). HTTP APIs run about $1.00 per million requests. This should put our testing in the less than $.01 category.
- Create the HTTP API from the console:
- Open API Gateway in the AWS Console.
- Click Create an API and under HTTP API, click Build.
- Enter the API name
patientping-ip-api. - Under Integrations, click “Add” and use Lambda as the integration type.
- Select
patientping-ip-function - Click Next.
- Configure routes: add a route with Method
GET, Resource path/, and Integration target the same Lambda (patientping-ip-function). - Click Next.
- Leave Stage name as
$default, leave Auto-deploy enabled. - lick Next, review, then Create.
- Test the API:
- Navigate to “Deploy” → “Stages” in the left sidebar in the API Gateway console, and click on the stage named
$default. - Copy the “invoke URL” and paste it into your browser. You should get a live response with your real IP address!
- Navigate to “Deploy” → “Stages” in the left sidebar in the API Gateway console, and click on the stage named