How to create an API using an AWS Lambda & API Gateway in 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.
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 email@example.com:delasign/typescript-serverless-starter.git
Step One: Add the events to the function
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
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
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.
We are actively looking for feedback on how to improve this resource. Please send us a note to firstname.lastname@example.org with any thoughts or feedback you may have.