Serverless Architectures with AWS - Mohit Gupta - E-Book

Serverless Architectures with AWS E-Book

Mohit Gupta

0,0
23,99 €

-100%
Sammeln Sie Punkte in unserem Gutscheinprogramm und kaufen Sie E-Books und Hörbücher mit bis zu 100% Rabatt.

Mehr erfahren.
Beschreibung

Serverless Architecture with AWS begins with an introduction to the serverless model and helps you get started with AWS and Lambda. You'll also get to grips with other capabilities of the AWS Serverless Platform and see how AWS supports enterprise-grade serverless applications with and without Lambda.

This book will guide you in deploying your first serverless project and exploring the capabilities of serverless Amazon Athena, an interactive query service that makes it easy to analyze data in Amazon Simple Storage Service (S3 Amazon) using standard SQL. You’ll also learn about AWS Glue, a fully managed ETL service that makes categorizing data easy and cost-effective. You'll study how Amazon Kinesis makes it possible to unleash the potential of real-time data insights and analytics with capabilities such as video streams, data streams, data firehose, and data analytics. Last but not least, you’ll be equipped to combine Amazon Kinesis capabilities with AWS Lambda to create lightweight serverless architectures.

By the end of the book, you will be ready to create and run your first serverless application that takes advantage of the high availability, security, performance, and scalability of AWS.

Das E-Book können Sie in Legimi-Apps oder einer beliebigen App lesen, die das folgende Format unterstützen:

EPUB
MOBI

Seitenzahl: 141

Veröffentlichungsjahr: 2018

Bewertungen
0,0
0
0
0
0
0
Mehr Informationen
Mehr Informationen
Legimi prüft nicht, ob Rezensionen von Nutzern stammen, die den betreffenden Titel tatsächlich gekauft oder gelesen/gehört haben. Wir entfernen aber gefälschte Rezensionen.



Serverless Architectures with AWS

Discover how you can migrate from traditional deployments to serverless architectures with AWS

Mohit Gupta

Serverless Architectures with AWS

Copyright © 2018 Packt Publishing

All rights reserved. No part of this book may be reproduced, stored in a retrieval system, or transmitted in any form or by any means, without the prior written permission of the publisher, except in the case of brief quotations embedded in critical articles or reviews.

Every effort has been made in the preparation of this book to ensure the accuracy of the information presented. However, the information contained in this book is sold without warranty, either express or implied. Neither the author, nor Packt Publishing, and its dealers and distributors will be held liable for any damages caused or alleged to be caused directly or indirectly by this book.

Packt Publishing has endeavored to provide trademark information about all of the companies and products mentioned in this book by the appropriate use of capitals. However, Packt Publishing cannot guarantee the accuracy of this information.

Author: Mohit Gupta

Reviewer: Amandeep Singh

Managing Editor: Edwin Moses

Acquisitions Editor: Aditya Date

Production Editor: Nitesh Thakur

Editorial Board: David Barnes, Ewan Buckingham, Simon Cox, Manasa Kumar, Alex Mazonowicz, Douglas Paterson, Dominic Pereira, Shiny Poojary, Saman Siddiqui, Erol Staveley, Ankita Thakur, and Mohita Vyas.

First Published: December 2018

Production Reference: 1211218

Published by Packt Publishing Ltd.

Livery Place, 35 Livery Street

Birmingham B3 2PB, UK

ISBN 978-1-78980-502-4

Table of Contents

Preface   i

AWS, Lambda, and Serverless Applications   1

Introduction   2

The Serverless Model   2

Benefits of the Serverless Model   5

Introduction to AWS   6

AWS Serverless Ecosystem   7

AWS Lambda   8

Supported Languages   9

Exercise 1: Running Your First Lambda Function   10

Activity 1: Creating a New Lambda Function that Finds the Square Root of the Average of Two Input Numbers   16

Limits of AWS Lambda   17

AWS Lambda Pricing Overview   18

Lambda Free Tier   19

Activity 2: Calculating the Total Lambda Cost   20

Additional Costs   21

Summary   21

Working with the AWS Serverless Platform   23

Introduction   24

Amazon S3   24

Key Characteristics of Amazon S3   25

Deploying a Static Website   27

Exercise 2: Setting up a Static Website with an S3 Bucket Using a Domain Name in Route 53   28

Enabling Versioning on S3 Bucket   36

S3 and Lambda Integration   37

Exercise 3: Writing a Lambda Function to Read a Text File   37

API Gateway   42

What is API Gateway?   43

API Gateway Concepts   43

Exercise 4: Creating a REST API and Integrating It with Lambda   44

Other Native Services   51

Amazon SNS   51

Amazon SQS   53

DynamoDB   54

DynamoDB Streams   56

DynamoDB Streams Integration with Lambda   56

Exercise 5: Creating an SNS topic and Subscribing to It   57

Exercise 6: SNS Integration with S3 and Lambda   61

Activity 3: Setting Up a Mechanism to Get an Email Alert When an Object Is Uploaded into an S3 Bucket   66

Summary   67

Building and Deploying a Media Application   69

Introduction   70

Designing a Media Web Application – from Traditional to Serverless   70

Building a Simple Serverless Media Web Application   71

Exercise 7: Building the Role to Use with an API   72

Exercise 8: Creating an API to Push to / Get from an S3 Bucket   75

Exercise 9: Building the Image Processing System   89

Deployment Options in the Serverless Architecture   95

Activity 4: Creating an API to Delete the S3 Bucket   96

Summary   97

Serverless Amazon Athena and the AWS Glue Data Catalog   99

Introduction   100

Amazon Athena   100

Databases and Tables   102

Exercise 10: Creating a New Database and Table Using Amazon Athena   103

AWS Glue   112

Exercise 11: Using AWS Glue to Build a Metadata Repository   114

Activity 5: Building an AWS Glue Catalog for a CSV-Formatted Dataset and Analyzing the Data Using AWS Athena   120

Summary   121

Real-Time Data Insights Using Amazon Kinesis   123

Introduction   124

Amazon Kinesis   124

Benefits of Amazon Kinesis   125

Amazon Kinesis Data Streams   125

How Kinesis Data Streams Work   126

Exercise 12: Creating a Sample Kinesis Stream   127

Amazon Kinesis Firehose   136

Exercise 13: Creating a Sample Kinesis Data Firehose Delivery Stream   138

Activity 6: Performing Data Transformations for Incoming Data   151

Amazon Kinesis Data Analytics   153

Exercise 14: Setting Up an Amazon Kinesis Analytics Application   155

Activity 7: Adding Reference Data to the Application and Creating an Output, and Joining Real-Time Data with the Reference Data   173

Summary   174

Appendix   177

To my children, Aarya and Naisha.

>

Preface

About

This section briefly introduces the author and reviewer, the coverage of this book, the technical skills you'll need to get started, and the hardware and software required to complete all of the included activities and exercises.

1

AWS, Lambda, and Serverless Applications

Learning Objectives

By the end of this chapter, you will be able to:

Explain the serverless modelDescribe the different AWS serverless services present in the AWS ecosystemCreate and execute an AWS Lambda function

This chapter teaches you the basics of serverless architectures, focusing on AWS.

Introduction

Imagine that a critical application in your company is having performance issues. This application is available to customers 24-7, and during business hours, the CPU and memory utilization reaches 100%. This is resulting in an increased response time for customers.

Around 10 years ago, a good migration plan to solve this issue would involve the procurement and deployment of new hardware resources for both the application and its databases, the installation of all required software and application code, performing all functional and performance quality analysis work, and finally, migrating the application. The cost of this would run into millions. However, nowadays, this issue can be resolved with new technologies that offer different approaches to customers – going Serverless is definitely one of them.

In this chapter, we'll start with an explanation of the serverless model, and get started with AWS and Lambda, the building blocks of a serverless applications on AWS. Finally, you'll learn how to create and run Lambda functions.

The Serverless Model

To understand the serverless model, let's first understand how we build traditional applications such as mobile applications and web applications. Figure 1.1 shows a traditional on-premises architecture, where you would take care of every layer of application development and the deployment process, starting with setting up hardware, software installation, setting up a database, networking, middleware configuration, and storage setup. Moreover, you would need a staff of engineers to set up and maintain this kind of on-premises setup, making it very time-consuming and costly. Moreover, the life cycle of these servers was no longer than 5-6 years, which meant that you would end up upgrading your infrastructure every few years.

The work wouldn't end there, as you would have to perform regular server maintenance, including setting up server reboot cycles and running regular patch updates. And despite doing all the groundwork and making sure that the system ran fine, the system would actually fail and cause application downtime. The following diagram shows a traditional on-premises architecture:

Figure 1.1 : Diagram of traditional on-premises architecture

The serverless model changes this paradigm completely, as it abstracts all the complexity attached with provisioning and managing data centers, servers, and software. Let's understand it in more detail.

The serverless model refers to applications in which server management and operational tasks are completely hidden from end users, such as developers. In the serverless model, developers are dedicated specifically to business code and the application itself, and they do not need to care about the servers where the application will be executed or run from, or about the performance of those servers, or any restrictions on them. The serverless model is scalable and is actually very flexible. With the serverless model, you focus on things that are more important to you, which is most probably solving business problems. The serverless model allows you to focus on your application architecture without you needing to think about servers.

Sometimes, the term "serverless" can be confusing. Serverless does not mean that you don't need any servers at all, but that you are not doing the work of provisioning servers, managing software, and installing patches. The term "the serverless model" just means that it is someone else's servers. Serverless architectures, if implemented properly, can provide great advantages in terms of lowering costs and providing operational excellence, thus improving overall productivity. However, you have to be careful when dealing with the challenges imposed by serverless frameworks. You need to make sure that your application doesn't have issues with performance, resource bottlenecks, or security.

Figure 1.2 shows the different services that are part of the serverless model. Here, we have different services for doing different kinds of work. We have the API Gateway service, a fully managed REST interface, which helps to create, publish, maintain, monitor, and secure APIs. Then, we have the AWS Lambda service that executes the application code and does all the computation work. Once computation is done, data gets stored in the DynamoDB database, which is again a fully managed service that provides a fast and scalable database management system. We also have the S3 storage service, where you can store all your data in raw formats that can be used later for data analytics. The following diagram talks about the serverless model:

Figure 1.2 : The serverless model (using AWS services)

Serverless models have become quite popular in recent times, and many big organizations have moved their complete infrastructure to serverless architectures and have been running them successfully, getting better performance a much a lower cost. Many serverless frameworks have been designed, making it easier to build, test, and deploy serverless applications. However, our focus in this book will be on serverless solutions built on Amazon Web Services (AWS). Amazon Web Services is a subsidiary of Amazon.com that provides on-demand cloud service platforms.

Benefits of the Serverless Model

There are a number of benefits to using a serverless model:

No server management: Provisioning and managing servers is a complex task and it can take anything from days to months to provision and test new servers before you can start using them. If not done properly, and with a specific timeline, it can become a potential obstacle for the release of your software onto the market. Serverless models provide great relief here by masking all the system engineering work from the project development team.High availability and fault tolerance: Serverless applications have built-in architecture that supports high availability (HA). So, you don't need to worry about the implementation of these capabilities. For example, AWS uses the concept of regions and availability zones to maintain the high availability of all AWS services. An availability zone is an isolated location inside a region and you can develop your application in such a way that, if one of the availability zones goes down, your application will continue to run from another availability zone.Scalability: We all want our applications to be successful, but we need to make sure that we are ready when there is an absolute need for scaling. Obviously, we don't want to spawn very big servers in the beginning (since this can escalate costs quickly), but we want to do it as and when the need occurs. With serverless models, you can scale your applications very easily. Serverless models run under the limits defined by you, so you can easily expand those limits in the future. You can adjust the computing power, the memory, or IO needs of your application with just a few clicks, and you can do that within minutes. This will help you to control costs as well.Developer productivity: In a serverless model, your serverless vendor takes all the pain of setting up hardware, networking, and installing and managing software. Developers need to focus only on implementing the business logic and don't need to worry about underlying system engineering work, resulting in higher developer productivity.No idle capacity: With serverless models, you don't need to provision computing and storage capacity in advance. And you can scale up and down based on your application requirements. For example, if you have an e-commerce site, then you might need higher capacity during festive seasons than other days. So, you can just scale up resources for that period only.

Moreover, today's serverless models, such as AWS, work on the "pay as you go" model, meaning that you don't pay for any capacity that you don't use. This way, you don't pay anything when your servers are idle, which helps to control costs.

Faster time to market