How to create an API using an AWS Lambda & API Gateway in Serverless

Oscar de la Hera Gomez
A set of flowers that represent AWS Lambda, AWS API Gateway, Typescript and Serverless. Below them sits the text "AWS API using Serverless"

A step by step tutorial on creating an API using an AWS Lambda function and an API Gateway using Serverless. Github repository included.

The following tutorial builds off our Open Source starter project and walks you through how to create an API using an AWS Lambda function and an API Gateway through Serverless and Typescript.

Please note that this tutorial assumes that you have setup Serverless for deploying to AWS. For a comprehensive breakdown on how to do this, please follow the tutorial below.

Tutorial

We recommend downloading our Open Source project, checking out the main branch and carrying out the steps outlined below. All relevant changes can be found on the tutorial/lambda-hello-world branch.

git clone git@github.com:delasign/typescript-serverless-starter.git

Step One: Add the events to the function

A screenshot of VSCode showing our updated serverless.yml file with the code that's required to convert a function into an API. Code sample provided below.

In the case of this tutorial, we added the events to hello function making it use a POST HTTP request type, with a path /hello as well as using CORS.

Step Two: Deploy

A screenshot showing the results of our serverless deploy to AWS. It shows the URL of the API that we created.

In your terminal, set the current directory to that of the serverless project and run sls deploy.

At the end of the deploy, the console will inform you of the path of your API.

Please note that this requires you to have setup AWS credentials for your Serverless client.

Step Three: Verify

A screenshot of Postman showing the API that we created in this tutorial being called successfully.

Verify that your API call works using the information gathered in Step 2.

If you would like to learn how to make an API call in Postman, use the tutorial linked below.

Looking to add an API key?

Please consult the tutorial below to add an API key to your Serverless project.

Any Questions?

We are actively looking for feedback on how to improve this resource. Please send us a note to inquiries@delasign.com with any thoughts or feedback you may have.

delasign logo

Book a Free Consultation.

An icon of an email.

Click here to email us.

Fill in the details below to book a free consultation or to let us know about something else. Whatever it is, we are here to help.

How can we help you ?

Contact Details