Book Image

Serverless Design Patterns and Best Practices

By : Brian Zambrano
Book Image

Serverless Design Patterns and Best Practices

By: Brian Zambrano

Overview of this book

Serverless applications handle many problems that developers face when running systems and servers. The serverless pay-per-invocation model can also result in drastic cost savings, contributing to its popularity. While it's simple to create a basic serverless application, it's critical to structure your software correctly to ensure it continues to succeed as it grows. Serverless Design Patterns and Best Practices presents patterns that can be adapted to run in a serverless environment. You will learn how to develop applications that are scalable, fault tolerant, and well-tested. The book begins with an introduction to the different design pattern categories available for serverless applications. You will learn thetrade-offs between GraphQL and REST and how they fare regarding overall application design in a serverless ecosystem. The book will also show you how to migrate an existing API to a serverless backend using AWS API Gateway. You will learn how to build event-driven applications using queuing and streaming systems, such as AWS Simple Queuing Service (SQS) and AWS Kinesis. Patterns for data-intensive serverless application are also explained, including the lambda architecture and MapReduce. This book will equip you with the knowledge and skills you need to develop scalable and resilient serverless applications confidently.
Table of Contents (18 chapters)
Title Page
Copyright and Credits
Dedication
Packt Upsell
Contributors
Preface
Index

Resizing images in parallel


This example will be implemented in Node.js for no other reason than to change things from the Python code in previous chapters. There is a single dependency in this example, which we use for the image resizing, called jimp. I'll touch on some of the steps to get going with a new Node project using the Serverless Framework.

Setting up the project

Setting up a new Node.js project isn't any different from doing so with any other supported language. We'll tell serverless to use the aws-nodejs template and name our project fanout. The -p argument simply tells Serverless to place all of the generated code in the serverless directory, which is relative to the location where we execute this command. Consider the following code:

root@4b26ed909d56:/code# sls create -t aws-nodejs -p serverless -n fanout

Next, we'll add our single dependency for jimp. Here, I'm using yarn, but npm works fine as well:

root@4b26ed909d56:/code/serverless# yarn add jimp
yarn add v1.3.2 
info No lockfile...