In this article we’ll be looking at how we can quickly and easily build an API with TypeScript and Serverless.

We’ll then learn how to use the aws-sdk to access other AWS services and create an automatic translation API.

If you prefer to watch and learn, you can check out the video below:

Getting started

To start this whole process we need to make sure that we have the Serverless Framework installed and have an AWS profile set up on our computer. If you haven’t then you can check out this video on how to get that all set up.

If you want to follow along with this tutorial you can follow all the steps or download the code here and follow with the completed code.

Now we’re onto creating our serverless project and API. We need to start in a terminal and run the command to create our new repo. All you need to do is to switch out the {YOUR FOLDER NAME} for the name of your folder.

serverless create --template aws-nodejs-typescript --path {YOUR FOLDER NAME}

This will create a very basic serverless project with TypeScript. If we open this new folder with VS Code then we can see what the template has given us.

The main files we want to look at are the serverless.ts file and the handler.ts file.

The serverless.ts file is where the configuration for the deployment is held. This file tells the serverless framework the project name, the runtime language of the code, the list of functions and a few other configuration options.

Whenever we want to change the architecture of our project this is the file we’ll be working in.

The next file is the handler.ts file. Here we have the example code for a lambda given to us by the template. It is very basic and just returns an API Gateway response with a message and the input event. We’ll be using this later as a starting block for our own API.

#typescript #aws #api #web-development #serverless

The Complete Guide to building an API with TypeScript, Serverless and AWS
2.05 GEEK