Book Image

Building Serverless Web Applications

By : Diego Zanon
Book Image

Building Serverless Web Applications

By: Diego Zanon

Overview of this book

This book will equip you with the knowledge needed to build your own serverless apps by showing you how to set up different services while making your application scalable, highly available, and efficient. We begin by giving you an idea of what it means to go serverless, exploring the pros and cons of the serverless model and its use cases. Next, you will be introduced to the AWS services that will be used throughout the book, how to estimate costs, and how to set up and use the Serverless Framework. From here, you will start to build an entire serverless project of an online store, beginning with a React SPA frontend hosted on AWS followed by a serverless backend with API Gateway and Lambda functions. You will also learn to access data from a SimpleDB database, secure the application with authentication and authorization, and implement serverless notifications for browsers using AWS IoT. This book will describe how to monitor the performance, efficiency, and errors of your apps and conclude by teaching you how to test and deploy your applications.
Table of Contents (17 chapters)
Title Page
Credits
About the Author
About the Reviewer
www.PacktPub.com
Customer Feedback
Preface

Going beyond the basics


In this section, we will explore what more we can do using the Serverless Framework.

Using npm packages

When you use the Serverless Framework to deploy your Lambda function, it creates a ZIP file with everything that is inside your project folder. If you need to use a module that is not a Node.js core module or the AWS SDK, you just need to use Node's default workflow to add dependencies.

Take a look at the following steps:

  1. Create a package.json file to store your project dependencies and use npm install <your-module> --save to download your required module.
  2. With the node_modules folder inside your project directory, the ZIP file will be deployed to AWS with the necessary dependencies.
  3. In the following example, the Lambda function of the file handle.js uses an npm module called cat-names:
        module.exports.catNames = (event, context, callback) => {

const catNames = require('cat-names');

          const response = {
            statusCode: 200,   
       ...