Reader small image

You're reading from  Mastering TypeScript - Fourth Edition

Product typeBook
Published inApr 2021
Reading LevelIntermediate
PublisherPackt
ISBN-139781800564732
Edition4th Edition
Languages
Right arrow
Author (1)
Nathan Rozentals
Nathan Rozentals
author image
Nathan Rozentals

Nathan Rozentals has been writing commercial software for over 30 years, in C, C++, Java and C#. He picked up TypeScript within a week after its initial release in October 2012 and realized how much TypeScript could help when writing JavaScript. He was one of the first people to start blogging about TypeScript, discussing early frameworks such as Backbone, Marionette, ExtJS and AngularJs. He knew he'd hit the mark when Microsoft staff started to reference his blog posts in their CodePlex discussion forums. Nathan's TypeScript solutions now control User Interfaces in IoT devices, run as stand-alone applications for Point-of-Sale solutions, provide complex application configuration web sites, and are used for mission-critical server APIs.
Read more about Nathan Rozentals

Right arrow

An AWS Serverless API

Node has been rather a game changer in the web application world. One of the reasons for this is the lightweight hardware specifications that are needed to run a Node web server. Traditionally, web server engines, such as Apache, or Microsoft's IIS web server, needed some pretty beefy servers in order to accommodate thousands of HTTP requests per second.

Node, as we have discussed, uses a single-threaded architecture, and each instruction that needs to wait, for any reason, is put onto a queue for processing at a later time. This means that the server is only running a single thread of execution at any particular time, and therefore can handle a large number of simultaneous requests with a surprisingly little amount of CPU or RAM. In the modern age of cloud computing, this means that many more Node web servers can be run on a single piece of physical hardware, compared to other traditional web servers.

Most cloud services, including Azure, Google...

Serverless setup

In this section of the chapter, we will set up a serverless development environment using the Amazon Serverless Application Model command-line interface. We will use this command-line interface to initialize an API application, which will also generate some sample code for us. We will then deploy this application to the cloud, again using the command-line interface.

AWS Lambda architecture

Before we go ahead and build a Lambda function, let's explore the pieces of the AWS architecture that we will use in order to respond to a web request. These elements are shown in the following diagram:

Figure 15.1: AWS Lambda architectural components

Here, we start with a client request, on the far left-hand side of the diagram. This request takes the form of an HTTP request for a GET call on the /users API endpoint. The first architectural element that will respond to this request is Amazon API Gateway. Amazon API Gateway is an AWS service that is used...

Building an API

Now that we have a working AWS SAM CLI environment configured, we can build an API. The API that we will build in this chapter will be used to support the three existing applications that we have been building throughout this book, in Angular, React, and Vue. Our Angular application, which we built in Chapter 11, Angular, revolved around a user logging in to an application. This means that we will need to store and retrieve user details from a database.

The React application that we built in Chapter 12, React, showed a list of products for sale, and when a particular product was chosen, it would show the details of the product. To support this, we will need to store and then retrieve our products from a database, and allow for the generation of a list of available products. We also included the option of selecting how many of these products to add to a shopping cart.

The Vue application that we built in Chapter 13, Vue, was responsible for displaying a user...

Summary

In this chapter, we have covered the architecture of an AWS Lambda function and installed the SAM CLI to help us to generate Lambda functions, deploy Lambda functions, and run them locally. We have also discussed the DynamoDB database, and worked through some examples of using NoSQL Workbench to generate code for us, which we can use to interact with our data. We also created a few TypeScript-based Lambda functions, which were able to use either data sent as part of a POST operation or path parameters to guide their behavior.

In the next, and final, chapter of this book, we will combine the work that we have done over the past few chapters into a single application using micro front-end techniques.

lock icon
The rest of the chapter is locked
You have been reading a chapter from
Mastering TypeScript - Fourth Edition
Published in: Apr 2021Publisher: PacktISBN-13: 9781800564732
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.
undefined
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 $15.99/month. Cancel anytime

Author (1)

author image
Nathan Rozentals

Nathan Rozentals has been writing commercial software for over 30 years, in C, C++, Java and C#. He picked up TypeScript within a week after its initial release in October 2012 and realized how much TypeScript could help when writing JavaScript. He was one of the first people to start blogging about TypeScript, discussing early frameworks such as Backbone, Marionette, ExtJS and AngularJs. He knew he'd hit the mark when Microsoft staff started to reference his blog posts in their CodePlex discussion forums. Nathan's TypeScript solutions now control User Interfaces in IoT devices, run as stand-alone applications for Point-of-Sale solutions, provide complex application configuration web sites, and are used for mission-critical server APIs.
Read more about Nathan Rozentals