Building Serverless Applications with Python - Jalem Raj Rohit - E-Book

Building Serverless Applications with Python E-Book

Jalem Raj Rohit

0,0
32,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

Building efficient Python applications at minimal cost by adopting serverless architectures


Key Features Design and set up a data flow between cloud services and custom business logic Make your applications efficient and reliable using serverless architecture Build and deploy scalable serverless Python APIsBook Description


Serverless architectures allow you to build and run applications and services without having to manage the infrastructure. Many companies have adopted this architecture to save cost and improve scalability. This book will help you design serverless architectures for your applications with AWS and Python.


The book is divided into three modules. The first module explains the fundamentals of serverless architecture and how AWS lambda functions work. In the next module, you will learn to build, release, and deploy your application to production. You will also learn to log and test your application. In the third module, we will take you through advanced topics such as building a serverless API for your application. You will also learn to troubleshoot and monitor your app and master AWS lambda programming concepts with API references. Moving on, you will also learn how to scale up serverless applications and handle distributed serverless systems in production.


By the end of the book, you will be equipped with the knowledge required to build scalable and cost-efficient Python applications with a serverless framework.


What you will learn Understand how AWS Lambda and Microsoft Azure Functions work and use them to create an application Explore various triggers and how to select them, based on the problem statement Build deployment packages for Lambda functions Master the finer details about building Lambda functions and versioning Log and monitor serverless applications Learn about security in AWS and Lambda functions Scale up serverless applications to handle huge workloads and serverless distributed systems in production Understand SAM model deployment in AWS LambdaWho this book is for


This book is for Python developers who would like to learn about serverless architecture. Python programming knowledge is assumed.


Jalem Raj Rohit is an IIT Jodhpur graduate with a keen interest in recommender systems, machine learning, and serverless and distributed systems. Raj currently works as a senior consultant—data science—and NLP at Episource, before which he worked at Zomato and Kayako. He contributes to open source projects in Python, Go, and Julia. He also speaks at tech conferences about serverless engineering and machine learning.

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

EPUB

Seitenzahl: 136

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.



Building Serverless Applications with Python

 

 

 

 

 

 

 

 

 

 

 

Develop fast, scalable, and cost-effective web applications that are always available

 

 

 

 

 

 

 

 

 

Jalem Raj Rohit

 

 

 

 

 

 

 

 

 

 

BIRMINGHAM - MUMBAI

Building Serverless Applications with Python

 

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 or its dealers and distributors, will be held liable for any damages caused or alleged to have been 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.

Commissioning Editor: Merint MathewAcquisition Editor: Sandeep MishraContent Development Editor: Rohit Kumar SinghTechnical Editor: Ruvika RaoCopy Editor: Safis EditingProject Coordinator: Vaidehi SawantProofreader: Safis EditingIndexer: Priyanka DhadkeGraphics: Jason MonteiroProduction Coordinator: Arvindkumar Gupta

First published: April 2018

Production reference: 1190418

Published by Packt Publishing Ltd. Livery Place 35 Livery Street Birmingham B3 2PB, UK.

ISBN 978-1-78728-867-6

www.packtpub.com

mapt.io

Mapt is an online digital library that gives you full access to over 5,000 books and videos, as well as industry leading tools to help you plan your personal development and advance your career. For more information, please visit our website.

Why subscribe?

Spend less time learning and more time coding with practical eBooks and Videos from over 4,000 industry professionals

Improve your learning with Skill Plans built especially for you

Get a free eBook or video every month

Mapt is fully searchable

Copy and paste, print, and bookmark content

PacktPub.com

Did you know that Packt offers eBook versions of every book published, with PDF and ePub files available? You can upgrade to the eBook version at www.PacktPub.com and as a print book customer, you are entitled to a discount on the eBook copy. Get in touch with us at [email protected] for more details.

At www.PacktPub.com, you can also read a collection of free technical articles, sign up for a range of free newsletters, and receive exclusive discounts and offers on Packt books and eBooks.

Contributors

About the author

Jalem Raj Rohit is an IIT Jodhpur graduate with a keen interest in recommender systems, machine learning, and serverless and distributed systems. Raj currently works as a senior consultant—data science—and NLP at Episource, before which he worked at Zomato and Kayako. He contributes to open source projects in Python, Go, and Julia. He also speaks at tech conferences about serverless engineering and machine learning.

About the reviewer

Sanjeev Jaiswal is a computer graduate from CUSAT with 9 years of industrial experience. He basically uses Perl, Python, AWS, and GNU/Linux for his day-to-day activities. He is currently working on projects involving penetration testing, source code review, security design and implementations in AWS, and cloud security projects.

He is learning DevSecOps and Security Automation currently as well. Sanjeev loves teaching engineering students and IT professionals. He has been teaching in his leisure time for the last 8 years.

Special thanks to my wife, Shalini Jaiswal, for her unconditional support, and my friends Ranjan, Ritesh, Mickey, Shankar, and Santosh for their care and support all the time. Thanks to the people at Packt for the project and the opportunity to learn good stuff from skilled professionals through reviewing the project.

 

 

 

Packt is searching for authors like you

If you're interested in becoming an author for Packt, please visit authors.packtpub.com and apply today. We have worked with thousands of developers and tech professionals, just like you, to help them share their insight with the global tech community. You can make a general application, apply for a specific hot topic that we are recruiting an author for, or submit your own idea.

Table of Contents

Title Page

Copyright and Credits

Building Serverless Applications with Python

Packt Upsell

Why subscribe?

PacktPub.com

Contributors

About the author

About the reviewer

Packt is searching for authors like you

Preface

Who this book is for

What this book covers

To get the most out of this book

Conventions used

Get in touch

Reviews

The Serverless Paradigm

Understanding serverless architectures

Understanding microservices

Serverless architectures don't have to be real-time only

Pros and cons of serverless

Summary

Building a Serverless Application in AWS

Triggers in AWS Lambda

Lambda functions

Functions as containers

Configuring functions

Testing Lambda functions

Versioning Lambda functions

Creating deployment packages

Summary

Setting Up Serverless Architectures

S3 trigger

SNS trigger

SQS trigger

CloudWatch trigger

Summary

Deploying Serverless APIs

API methods and resources

Setting up integration

Deploying the Lambda function for API execution

Handling authentication and user controls

Summary

Logging and Monitoring

Understanding CloudWatch

Understanding CloudTrail 

Lambda’s metrics in CloudWatch

Lambda's logs in CloudWatch

Logging statements in Lambda

Summary

Scaling Up Serverless Architectures

Third-party orchestration tools

The creation and termination of servers

Security best practices

Identifying and handling difficulties in scaling

Summary

Security in AWS Lambda

Understanding AWS Virtual Private Clouds (VPCs)

Understanding subnets in VPCs

Securing Lambda inside private subnets

Controlling access to Lambda functions

Using STS inside Lambda for secure session-based execution

Summary

Deploying a Lambda Function with SAM

Introduction to SAM

CloudFormation for serverless services

Deploying with SAM

Understanding security in SAM

Summary

Introduction to Microsoft Azure Functions

Introduction to Microsoft Azure Functions

Creating your first Azure Function

Understanding triggers

Understanding logging and monitoring in Azures Functions

Best practices for writing Azure Functions

Summary

Other Books You May Enjoy

Leave a review - let other readers know what you think

Preface

Serverless engineering is a new domain of engineering that allows developers to write code and deploy infrastructures without having to worry about maintaining servers. This book explains the concepts of serverless engineering with Python examples on cloud architectures.

Who this book is for

This book is for Python developers who would like to learn about serverless architectures in cloud-based platforms such as Azure and Amazon Web Services (AWS). Python programming knowledge is assumed.

What this book covers

Chapter 1, The Serverless Paradigm, introduces the reader to the concepts of microservices and serverless architectures, and provides a clear understanding of the pros and cons.

Chapter 2, Building a Serverless Application in AWS, covers AWS Lambda and explains the concepts, workings, and the components involved in the tool in detail. It also explains the nuances involved in security, user controls, and versioning code inside Lambda.

Chapter 3, Setting Up Serverless Architectures, goes into further detail about the various triggers in AWS Lambda and how they integrate with the functions. The reader will learn what the event structure of each trigger will look like and how to modify the Lambda function with respect to the type of trigger used.

Chapter 4, Deploying Serverless APIs, explores the AWS API Gateway and also teaches the reader how to build efficient, scalable serverless APIs using the API Gateway and Lambda. It goes on to teach the reader how to improve the API by adding authorization and how to set up user-level controls such as throttling of requests.

Chapter 5, Logging and Monitoring, presents the concept of logging and monitoring in serverless applications. This is mostly still an unsolved problem in this domain. This chapter guides the reader through setting up logging and monitoring in the AWS environment with Python via custom metrics and logging. This chapter also goes into the details of best practices when it comes to logging and monitoring Lambda functions in Python.

Chapter 6, Scaling Up Serverless Architectures, discusses the practice of scaling up serverless architectures for large workloads using several third-party tools. This chapter also teaches the reader how to handle security, logging, and monitoring using the available Python modules.

Chapter 7, Security in AWS Lambda, teaches readers to deploy secure serverless applications by leveraging the AWS security features available. This involves having strict controls on components that the application can access, on the users who can handle or access the application, and so on. This also involves understanding AWS virtual private clouds and subnets for an in-depth understanding of the security features and best practices you can follow in AWS Lambda.

Chapter 8, Deploying a Lambda Function with SAM, looks at how to deploy Lambda functions as infrastructure as code via the Serverless Application Model, which is a new way of writing and deploying Lambda functions that makes it easier to integrate with other IaaS services, such as CloudFormation.

Chapter 9, Introduction to Microsoft Azure Functions, familiarizes the reader with Microsoft Azure Functions, and explains how to configure and understand the components of the tool.

To get the most out of this book

The reader should be comfortable with the Python programming language. So, prior experience with it is expected. Prior experience with cloud-based systems will also be helpful.

Conventions used

There are a number of text conventions used throughout this book.

CodeInText: Indicates code words in text, database table names, folder names, filenames, file extensions, pathnames, dummy URLs, user input, and Twitter handles. Here is an example: "It is to be noted that the meta information should always be included for all SAM, which includes AWSTemplateFormatVersion and Transform. This would tell CloudFormation that the code you have written is an AWS SAM code and a serverless application."

A block of code is set as follows:

AWSTemplateFormatVersion: '2010-09-09'Transform: AWS::Serverless-2016-10-31

Bold: Indicates a new term, an important word, or words that you see onscreen. For example, words in menus or dialog boxes appear in the text like this. Here is an example: "For creating a function, you need to click on the orange Create a function button on the right."

Warnings or important notes appear like this.
Tips and tricks appear like this.

Get in touch

Feedback from our readers is always welcome.

General feedback: Email [email protected] and mention the book title in the subject of your message. If you have questions about any aspect of this book, please email us at [email protected].

Errata: Although we have taken every care to ensure the accuracy of our content, mistakes do happen. If you have found a mistake in this book, we would be grateful if you would report this to us. Please visit www.packtpub.com/submit-errata, selecting your book, clicking on the Errata Submission Form link, and entering the details.

Piracy: If you come across any illegal copies of our works in any form on the Internet, we would be grateful if you would provide us with the location address or website name. Please contact us at [email protected] with a link to the material.

If you are interested in becoming an author: If there is a topic that you have expertise in and you are interested in either writing or contributing to a book, please visit authors.packtpub.com.

Reviews

Please leave a review. Once you have read and used this book, why not leave a review on the site that you purchased it from? Potential readers can then see and use your unbiased opinion to make purchase decisions, we at Packt can understand what you think about our products, and our authors can see your feedback on their book. Thank you!

For more information about Packt, please visit packtpub.com.

The Serverless Paradigm

Most probably, if you are reading this book, you have already heard about the serverless paradigm and the terms serverless engineering and serverless architecture. Nowadays, the way developers deploy applications has changed drastically, especially in the domain of data engineering and web development, thanks to event-based architectural designs, also called serverless architectures.

It is not uncommon to have idle resources and servers in production idle after the server workload has finished, or waiting for the next workload to come. This introduces a bit of redundancy in the infrastructure. What if there was no need for idle resources lying around when there is no workload? What if resources can be created when necessary and be destroyed once the work is done?

At the end of this chapter, you will understand how serverless architectures and functions as a service work, and how you can build them into your existing software infrastructure. You will also learn what microservices are, and decide whether microservices or serverless operations are well-suited for your architecture or not. You will also learn how to build serverless applications with Python on major cloud service providers, such as Amazon Web Services (AWS) and Microsoft's Azure.

This chapter will cover the following points:

Understanding serverless architectures

Understanding microservices

Serverless architectures don't have to be real-time only

Pros and cons of serverless architectures

Understanding serverless architectures

The concept of serverless architectures or serverless engineering revolves entirely around understanding the concept of functions as a service. The most technical and accurate definition of serverless computing on the internet is as follows:

"Serverless computing, also known as function as a service (FAAS), is a cloud computing and code execution model in which the cloud provider fully manages starting and stopping of a function's container platform as a service (PaaS)."

Now, let's go into the details of each part of that definition to understand the paradigm of serverless computing better. We shall start with the term function as a service. It means that every serverless model has a function that is executed on the cloud. These functions are nothing but blocks of code, that are executed depending on the trigger that is associated with the function. This is a complete list of triggers in the AWS Lambda environment:

Now let's understand what manages the starting and stopping of a function. Whenever a function is triggered via one of these available triggers, the cloud provider launches a container in which the function executes. Also, after the function is successfully executed the function has returned something, or if the function has run out of time, the container gets thatched away or destroyed. The thatching happens so that the container can be reused in the event of high demand and whenever there is very little time between two triggers. Now, we come to the next part of the sentence, the function's container. This means that the functions are launched and executed in containers. This is the standard definition of a container from Docker, a company that made the concept of containers very popular:

"A container image is a lightweight, stand-alone, executable package of a piece of software that includes everything needed to run it: code, runtime, system tools, system libraries, settings."

This helps in packaging the code, the runtime environment, and so on of the function into a single deployment package for seamless execution. The deployment package contains the main code file for the function, all the non-standard libraries which are required for the function to execute. The creation process of a deployment package looks very similar to that of a virtual environment in Python.