Building Serverless Architectures Learn The Intricacies and Nuances of Building Efficient Serverless Architectures First Published Edition Gurturk
Building Serverless Architectures Learn The Intricacies and Nuances of Building Efficient Serverless Architectures First Published Edition Gurturk
com
https://textbookfull.com/product/serverless-development-on-aws-
building-enterprise-scale-serverless-solutions-1st-edition-sheen-
brisals/
textbookfull.com
https://textbookfull.com/product/serverless-architectures-on-aws-
second-edition-meap-v06-peter-sbarski-yan-cui-ajay-nair/
textbookfull.com
https://textbookfull.com/product/beginning-ruby-3-from-beginner-to-
pro-4th-edition-carleton-dileo/
textbookfull.com
Legend Hunter 1st Edition Jennifer Rose Mcmahon [Mcmahon
https://textbookfull.com/product/legend-hunter-1st-edition-jennifer-
rose-mcmahon-mcmahon/
textbookfull.com
https://textbookfull.com/product/get-funded-the-startup-entrepreneurs-
guide-to-seriously-successful-fundraising-1st-edition-biggs/
textbookfull.com
BIRMINGHAM - MUMBAI
< html PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN"
"http://www.w3.org/TR/REC-html40/loose.dtd">
Building Serverless
Architectures
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.
ISBN 978-1-78712-919-1
www.packtpub.com
Credits
Technical Editor
Dhiraj Chandanshive
About the Author
Cagatay Gurturk is a software engineer, internet enterpreneur, and cloud
enthusiast.
I would like to express my gratitude to the many people who helped and
supported me throughout this book, and to all those who read, wrote,
offered comments, and assisted me in the editing, proofreading, and
designing of this book.
I would like to thank Martin Lindenburg for reviewing every line of this
book and bringing his German perfectionism.
And, finally, I would like to thank everyone who motivated me for this
work.
Visit https://textbookfull.com
now to explore a rich
collection of eBooks, textbook
and enjoy exciting offers!
About the Reviewer
Martin Lindenburg is a software engineer born in 1982. He grew up in a
rural region, about 100 km north of Berlin. He developed his interest in
computers and technology at a young age with his brother's Commodore64.
Later, he invested all his pocket money to afford his first own 386 computer,
where he developed his first programs in Basic and Turbo Pascal to
visualize and solve his math homework. This interest evolved, and, a few
years later, he finally ended up studying computer engineering in Berlin.
He is now working for more than ten years as a software engineer, and he has
worked for companies in the telecommunication group, Deutsche Telekom
AG, the financial portal, Wallstreet-Online AG, and the advertisement and
affiliate network, ADCELL. He collected experiences from the creation of
standalone applications over scalable dynamic webpages with hundreds of
users logging in up to millions of daily page views and tracking events.
Thanks to Cagatay Gurturk for letting me review his book and a special
thanks to my wife, Maria, and my children, Samuel and Simon, for their
patience in the evenings when I had to review new chapters.
www.PacktPub.com
For support files and downloads related to your book, please visit www.PacktP
ub.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.comand 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.
https://www.packtpub.com/mapt
Get the most in-demand software skills with Mapt. Mapt gives you full
access to all Packt books and video courses, as well as industry-leading
tools to help you plan your personal development and advance your career.
Why subscribe?
Fully searchable across every book published by Packt
Copy and paste, print, and bookmark content
On demand and accessible via a web browser
Customer Feedback
Thanks for purchasing this Packt book. At Packt, quality is at the heart of our
editorial process. To help us improve, please leave us an honest review on
this book's Amazon page at https://www.amazon.com/dp/1787129195.
If you'd like to join our team of regular reviewers, you can e-mail us at
[email protected]. We award our regular reviewers with free
eBooks and videos in exchange for their valuable feedback. Help us be
relentless in improving our products!
Table of Contents
Preface
What this book covers
What you need for this book
Who this book is for
Conventions
Reader feedback
Customer support
Downloading the example code
Errata
Piracy
Questions
1. Getting Started with Serverless
Preparing the environment
Installing AWS CLI
Prerequisites
Gradle
Creating the project
Implementing the Lambda Dependency
Hello Lambda!
Deploying to the Cloud
Summary
Bibliography
2. Infrastructure as a Code
Uploading the artifacts to Cloud
Infrastructure as Code with CloudFormation
Deploying our first Lambda with CloudFormation
Summary
3. Hello Internet
Setting up API Gateway
Creating the API
Creating the resource
Creating the method
Configuring Lambda permissions
Deploying the API
Setting up the CloudFront CDN distribution
Setting up the custom domain
Creating an SSL certificate
Authenticating API calls
Implementing basic authorization
Summary
4. Applying Enterprise Patterns
Creating User Service
Configuring Guice
Writing the Lambda Handler class with injected dependency
Adding logging
Service dependencies
Summary
5. Persisting Data
Introduction to DynamoDB
Creating the first table
Creating the second table for access tokens
Configuring the DynamoDB data mapper
Configuring environment variables for Lambda
User registration
Creating user registration Lambda
Creating the Lambda and API Gateway for User Registration
Summary
6. Building Supporting Services
Writing the foundation of a Lambda function
Letting users upload to S3
Modifying the Lambda function to respond to an S3 event
Configuring CloudFront to serve resized images
Excercise
Sending emails via SES
Configuring SES
Firing an SNS notification upon user registration
Consuming the SNS message and sending emails
Integrating a messaging queue
Summary
7. Searching Data
Creating the search domain
Uploading test data
Creating the suggester
Creating the API endpoint for suggestions
Lambda function for updating search data
Modifying the welcome mail sender Lambda
Creating the Lambda function to update CloudSearch
Creating and configuring the Lambda function with CloudFormat
ion
Summary
8. Monitoring, Logging, and Security
Setting up a Route53 health check
Starting off with the setup
Configuring health checks for email notifications
Enabling SMS notifications for health checks
Bringing health check to healthy mode
Mastering CloudWatch alarms
Configuring advanced CloudWatch alarms
Wrapping everything up in CloudFormation
Creating CloudWatch metrics from application logs
Running Lambda functions in VPC
Creating a VPC
Adding private subnets
Handling inbound and outbound traffic
Creating a Security Group
Summary
9. Lambda Framework
Getting to know Lambda Framework
Summary
Preface
Over the past few years, all kind of companies, ranging from start-ups to
giant enterprises, have started their move to public cloud providers in order
to save their costs and reduce the operational effort needed to keep their
shops open. While this movement was applied with just a lift and shift
strategy, keeping their software architecture the same and only changing
where they are hosting it, some companies opted for a mindset change,
modifying their software to take advantage of native cloud services other
than virtual machines, changing their team structures, and adopting DevOps
practices. This opened the door to many changes in the software industry, and
it is definitely possible to say that the world after the introduction of cloud
computing is not the same as before.
The focus of this book is to design serverless architectures, and weigh the
advantages and disadvantages of this approach, along with a few decision
factors to consider. You will learn how to design a serverless application,
get to know the key points of services that serverless applications are based
on, and known issues and solutions. In this book, you will not only learn the
AWS Lambda functions, but you will also see how to use the Lambda
functions to glue other AWS services together. You will learn how easy it is
to build a scalable software system is, taking a CRUD application as an
example.
The book addresses key challenges, such as how to slice out the core
functionality of the software to be distributed in different cloud services and
cloud functions. It covers the basic and advanced usage of these services,
testing and securing the serverless software, automating deployment, and
more.
Throughout this book, we will only use the Java programming language, and
we will build a homegrown deployment system to easily deploy our
software.
This book does not intend to cover all the details of the AWS ecosystem, but I
believe it will perfectly show you the path through the serverless computing
world.
What this book covers
Chapter 1,Getting Started With Serverless, introduces you to serverless
computing and Lambda functions, sets up the AWS account and environment,
and builds the base libraries.
Chapter 3,
Hello Internet, exposes the Lambda function to the internet via the
AWS API Gateway.
Chapter 4,
Applying Enterprise Patterns, implements and configures the
dependency injection pattern for the Lambda function.
Appendix,
Lambada Framework, migrates your JAX-RS application to AWS
Lambda and API Gateway with minimal effort.
Visit https://textbookfull.com
now to explore a rich
collection of eBooks, textbook
and enjoy exciting offers!
What you need for this book
To run all the code in this book, you only need to have the Java Development
Kit installed on your machine. You will have to create an AWS account to
apply the steps. AWS offers a free tier for new customers that will cover
most of the costs of running examples in the book. On the other hand, some
services such as CloudSearch and VPC NAT Gateways are not covered by a
free tier. Make sure that you visit the pricing documentation of each service
used in the book to avoid unnecessary costs.
Who this book is for
This book is for developers and software architects who are interested in
designing their software in serverless environments. Since the programming
language used in this book is Java, it is preferred that readers are familiar
with the basics of Java and the general conventions used in the Java world.
Conventions
In this book, you will find a number of text styles that distinguish between
different kinds of information. Here are some examples of these styles and an
explanation of their meaning.
Code words in text, database table names, folder names, filenames, file
extensions, pathnames, dummy URLs, user input, and Twitter handles are
shown as follows: "We can start by adding the next snippet to the
build.gradle file."
cloudFormation {
capabilityIam true
templateFile project.file('cloudformation.template')
templateBucket deploymentBucketName
templateKeyPrefix "cfn-templates"
stackName "serverlessbook"
}
$ touch cloudformation.template
New terms and important words are shown in bold. Words that you see on
the screen, for example, in menus or dialog boxes, appear in the text like this:
"In order to download new modules, we will go to Files | Settings | Project
Name | Project Interpreter."
72
Chapter VI
Penn’s Arrival—The Founding of Philadelphia—First General
Assembly—Building of the “Blue Anchor”—The First School
and Printing Press
84
Chapter VII
The Indian Conference—Signing of the Treaty—Penn Returns to
England to Defend his Rights against Lord Baltimore—
Accession of James the Second—His Dethronement and
Accession of William the Third
96
Chapter VIII
Penn Tried for Treason and Acquitted—Withdrawal of Penn’s
Charter—Death of his Wife and Son—Second Marriage—
Journey to America—Penn’s Home—Attempts to Correct
Abuses—Returns to England and Encounters Fresh Dangers
—Penn in the Debtors’ Prison—Ingratitude of the Colonists