Professional Documents
Culture Documents
PDF Ai As A Service Serverless Machine Learning With Aws 1St Edition Peter Elger Ebook Full Chapter
PDF Ai As A Service Serverless Machine Learning With Aws 1St Edition Peter Elger Ebook Full Chapter
https://textbookfull.com/product/ai-as-a-service-serverless-
machine-learning-with-aws-1st-edition-peter-elger-eoin-shanaghy-
shanaghy-eoin/
https://textbookfull.com/product/self-service-ai-with-power-bi-
desktop-machine-learning-insights-for-business-markus-
ehrenmueller-jensen/
https://textbookfull.com/product/practical-machine-learning-with-
aws-process-build-deploy-and-productionize-your-models-using-
aws-1st-edition-himanshu-singh/
https://textbookfull.com/product/practical-machine-learning-with-
aws-process-build-deploy-and-productionize-your-models-using-aws-
himanshu-singh/
Serverless Architectures on AWS Second Edition MEAP V06
Peter Sbarski Yan Cui Ajay Nair
https://textbookfull.com/product/serverless-architectures-on-aws-
second-edition-meap-v06-peter-sbarski-yan-cui-ajay-nair/
https://textbookfull.com/product/serverless-development-on-aws-
building-enterprise-scale-serverless-solutions-1st-edition-sheen-
brisals/
https://textbookfull.com/product/data-science-on-aws-
implementing-end-to-end-continuous-ai-and-machine-learning-
pipelines-early-edition-chris-fregly/
https://textbookfull.com/product/practical-machine-learning-
with-h2o-powerful-scalable-techniques-for-deep-learning-and-
ai-1st-edition-darren-cook/
https://textbookfull.com/product/practical-machine-learning-
with-h2o-powerful-scalable-techniques-for-deep-learning-and-ai-
first-edition-cook/
Serverless machine learning with AWS
Peter Elger
Eóin Shanaghy
MANNING
AI as a Service
Serverless machine learning with AWS
ii
AI as a Service
SERVERLESS MACHINE LEARNING WITH AWS
PETER ELGER
EÓIN SHANAGHY
MANNING
SHELTER ISLAND
For online information and ordering of this and other Manning books, please visit
www.manning.com. The publisher offers discounts on this book when ordered in quantity.
For more information, please contact
Special Sales Department
Manning Publications Co.
20 Baldwin Road
PO Box 761
Shelter Island, NY 11964
Email: orders@manning.com
Many of the designations used by manufacturers and sellers to distinguish their products are
claimed as trademarks. Where those designations appear in the book, and Manning
Publications was aware of a trademark claim, the designations have been printed in initial caps
or all caps.
Recognizing the importance of preserving what has been written, it is Manning’s policy to have
the books we publish printed on acid-free paper, and we exert our best efforts to that end.
Recognizing also our responsibility to conserve the resources of our planet, Manning books
are printed on paper that is at least 15 percent recycled and processed without the use of
elemental chlorine.
ISBN 9781617296154
Printed in the United States of America
For my parents, Noel and Kay—Eóin
For my daughters Isobel and Katie, my parents Jacky and Julian,
and my brother Jonathon—Peter
vi
contents
foreword xiii
preface xv
acknowledgments xvii
about this book xix
about the authors xxii
about the cover illustration xxiii
AI challenges 27
vii
viii CONTENTS
Off-platform 30
1.7 Realization on Amazon Web Services 30
2.2 Architecture 34
Web application 36 Synchronous services 37 Asynchronous
■ ■
support 41
2.3 Getting ready 41
DNS domain and SSL/TLS certificate 42 Setup checklist
■
44
Get the code 44 Setting up cloud resources 44
■
Analysis service 58
3.2 Implementing the synchronous services 62
UI service 62 ■
Front end service 67
3.3 Running the system 71
3.4 Removing the system 74
4.2 Architecture 80
Web application 82 Synchronous services 83 Asynchronous
■ ■
frontier 224
8.6 Building the fetcher to retrieve and parse web pages 224
Configuring and controlling a headless browser 225
Capturing page output 226 Fetching multiple pages
■
227
Deploying and testing the fetcher 228
8.7 Determining the crawl space in a strategy service 229
8.8 Orchestrating the crawler with a scheduler 231
Grabbing the code 232 Using Step Functions
■
232
Deploying and testing the scheduler 234
with a dead letter queue (DLQ) 246 Creating the DLQ and retry
■
index 291
foreword
For the past two decades, AI has played an increasingly significant role in our lives. It
has done so quietly behind the scenes, as AI technologies have been employed by
companies around the world to improve search results, product recommendations,
and advertising, and even to assist healthcare workers to provide a better diagnosis.
AI technologies are all around us, and soon, we’ll all travel in cars that drive
themselves!
With this rise in prominence came a rise in demand for relevant skills. Engineers
with expertise in machine learning or deep learning are often hoovered up by the big
tech companies at huge salaries. Meanwhile, every application on the surface of the
earth wants to use AI to improve its user experience. But the ability to hire the rele-
vant skillsets and acquire the necessary volume of data to train these AI models
remains a significant barrier to entry.
Fortunately, cloud providers are offering more and more AI services that remove
the need for you to steep yourself in the art of collecting and cleaning up data and
training AI models. AWS, for instance, lets you use the same technologies that power
product recommendations for Amazon.com through Amazon Personalize, or the
speech recognition technology that powers Alexa with Amazon Transcribe. Other
cloud providers (GCP, Azure, IBM, and so on) also offer similar services, and it will be
through these services that we will see AI-powered features in everyday applications.
And as these services become better and more accessible, there will be less need for
people to train their own AI models, except for more specialised workloads.
It’s great to finally see a book that focuses on leveraging these AI services rather
than the nitty-gritty details of training AI models. This book explains the important
concepts in AI and machine learning in layman’s terms, and describes them for
xiii
xiv FOREWORD
exactly what they are, without all the hype and hyperbole that often accompany
AI-related conversations. And the beauty of this book is that it is way more than “how
to use these AI services from AWS,” but also how to build applications the serverless
way. It covers everything from project organization, to continuous deployment, all the
way to effective logging strategies and how to monitor your application using both ser-
vice and application metrics. The later chapters of the book are also a treasure trove
of integration patterns and real-world examples of how to sprinkle some AI magic into
an existing application.
Serverless is a state of mind, a way of thinking about software development that
puts the needs of the business and its customers at the forefront, and aims to create
maximum business value with minimum effort by leveraging as many managed ser-
vices as possible. This way of thinking leads to increased developer productivity and
feature velocity, and often results in more scalable, resilient, and secure applications
by building on the shoulders of giants such as AWS.
Serverless is not the future of how we build businesses around software; it’s the
present and now, and it’s here to stay. This book will help you get started with Server-
less development and show you how to integrate AI services into a Serverless applica-
tion to enhance its user experience. Talk about hitting two birds with one stone!
YAN CUI
AWS SERVERLESS HERO
INDEPENDENT CONSULTANT
preface
The fourth industrial revolution is upon us! The coming decade will likely see huge
advances in areas such as gene editing, quantum computing, and, of course, artificial
intelligence (AI). Most of us already interact with AI technology on a daily basis. This
doesn’t just mean self-driving cars or automated lawn mowers. AI is far more pervasive
than these obvious examples. Consider the product recommendation that Amazon
just made when you visited their site, the online chat conversation you just had with
your airline to re-book a flight, or the text that your bank just sent you warning of a
possibly fraudulent transaction on your account. All of these examples are driven by
AI and machine learning technology.
Increasingly, developers will be required to add “smart” AI-enabled features and
interfaces to the products and platforms that they build. Early adopters of AI and
machine learning have been doing this for some time, of course; however, this
required a large investment in research and development, typically requiring a team
of data scientists to train, test, deploy, and operate custom AI models. This picture is
changing rapidly due to the powerful force of commoditization.
In his 2010 bestselling book, The Big Switch, Nicholas Carr compared cloud com-
puting to electricity, predicting that eventually we would consume computing
resources as a utility. Though we are not quite at the point of true utility computing, it
is becoming clearer that this consumption model is fast becoming a reality.
You can see this in the explosive growth in the range and capability of cloud-native
services. Commoditization of the cloud stack has given rise to the serverless comput-
ing paradigm. It is our belief that serverless computing will become the de facto stan-
dard architecture for building software platforms and products in the future.
In conjunction with the commoditization of the wider application stack, AI is also
rapidly becoming a commodity. Witness the number of AI services that are available
xv
xvi PREFACE
from the major cloud providers in areas such as image recognition, natural language
processing, and chatbot interfaces. These AI services grow in number and capability
month by month.
At our company, fourTheorem, we use these technologies on a daily basis to help
our clients extend and improve their existing systems through the application of AI
services. We help our clients to adopt serverless architectures and tools to accelerate
their platform development efforts, and we use our experience to help restructure
legacy systems so that they can run more efficiently on cloud.
It is the rapid growth and commoditization of these two technologies, Serverless
and AI services, along with our experience of applying them to real-world projects,
that led us to write this book. We wanted to provide an engineer’s guide to help you
succeed with AI as a Service, and we wish you luck as you begin to master this brave
new world of software development!
acknowledgments
Ask any technical book author ,and they will tell you that completing a book takes a
lot of time and effort. It also requires the fantastic support of others. We are incredibly
grateful for the many people who made completing this book possible.
First we would like to thank our families for their support, understanding, and
patience while we worked to complete the book. Eóin would like to thank his amazing
wife, Keelin, for her unending patience, moral support, and indispensable technical
reviews. He would also like to thank Aoife and Cormac for being the best children in
the world. Peter would like to thank his daughters, Isobel and Katie, just for being
awesome.
Eóin and Peter would like to thank fourTheorem co-founder Fiona McKenna for
her belief in this book, and her constant support and expertise in so many areas. We
could not have done it without you.
Starting a project like this is the hardest part, and we are grateful for the people
who helped in the beginning. Johannes Ahlmann contributed ideas, writing, and dis-
cussion that helped to shape what this book became. James Dadd and Robert Paulus
provided invaluable support and feedback.
We would also like to thank the awesome team at Manning for making this book
possible. In particular, we want to thank Lesley Trites, our development editor, for her
patience and support. We would also like to thank Palak Mathur and Al Krinker, our
technical development editors, for their review and feedback. Thank you to our proj-
ect editor, Deirdre Hiam; Ben Berg, our copyeditor; Melody Dolab, our proofreader,
and Ivan Martinović, our reviewing editor.
We would like to thank Yan Cui for writing the foreword to this book. Yan is an out-
standing architect and champion of all things serverless, and we are grateful for his
endorsement.
xvii
xviii ACKNOWLEDGMENTS
A big thanks to all of the reviewers for their feedback and suggestions for improve-
ment to the text and examples: Alain Couniot, Alex Gascon, Andrew Hamor, Dwight
Barry, Earl B. Bingham, Eros Pedrini, Greg Andress, Guillaume Alleon, Leemay Nass-
ery, Manu Sareena, Maria Gemini, Matt Welke, Michael Jensen, Mykhaylo Rubezhan-
skyy, Nirupam Sharma, Philippe Vialatte, Polina Keselman, Rob Pacheco, Roger M.
Meli, Sowmya Vajjala, Yvon Vieville,
A special thanks to Guillaume Alleon, technical proofreader, for his careful review
and testing of the code examples.
Finally we wish to acknowledge the broader open source community, of which we
are proud to participate in. We truly do stand on the shoulders of giants!
about this book
AI as a Service was written as an engineer’s guide to building AI-enabled platforms and
services. The aim of the book is to get you up and running, and able to produce
results quickly, without getting stuck in the weeds. AI and machine learning are big
topics, and there is an awful lot to learn if you wish to master these disciplines. It is not
our intent to discourage anyone from doing this, however if you need to get results
quickly, this book will help you get up to speed.
The book examines two growing and increasingly important technologies: server-
less computing and artificial intelligence. We examine these from a developer’s per-
spective to provide a practical, hands-on guide.
All of the major cloud vendors are engaged in a race to provide relevant AI ser-
vices, such as
Image recognition
Speech-to-text, text-to-speech
Chatbots
Language translation
Natural language processing
Recommendations
xix
xx ABOUT THIS BOOK
belief is that within the next few years, the tools, techniques, and architectures
described in this book will become part of the standard toolkit for enterprise platform
development. This book will bring you up to speed quickly, and help you build new sys-
tems using serverless architectures and to apply AI services to your existing platforms.
Chapter 9 looks at how we can extract value from large data sets using AI as a
Service, using the data collected from the serverless web crawler.
Readers should review the material in chapter 1 to get a basic grounding of the sub-
ject matter, and pay close attention to the content in chapter 2, where we describe
how to set up a development environment. The book is best read in order, as each
chapter builds on the examples and learning from the previous one.
EÓIN SHANAGHY was fortunate enough to have been able to start pro-
gramming on a Sinclair ZX Spectrum in the mid-1980s. It was the first
piece of electronics he didn’t try to disassemble. These days, he tries
to take software systems apart instead. Eóin is the CTO and
co-founder of fourTheorem, a technology consulting firm and AWS
Partner. He is an architect and developer with experience in building
and scaling systems for both startups and large enterprises. Eóin has
worked in many different technology eras, from Java-based distributed
systems back in 2000 to full-stack polyglot container and serverless applications in
recent years. Eóin holds a B.A. in computer science from Trinity College, Dublin.
xxii
about the cover illustration
The figure on the cover of AI as a Service is captioned “Homme de la Forêt Noire,” or
“The man from the Black Forest.” The illustration is taken from a collection of dress
costumes from various countries by Jacques Grasset de Saint-Sauveur (1757-1810),
titled Costumes civils actuels de tous les peuples connus, published in France in 1788. Each
illustration is finely drawn and colored by hand. The rich variety of Grasset de Saint-
Sauveur’s collection reminds us vividly of how culturally apart the world’s towns and
regions were just 200 years ago. Isolated from each other, people spoke different dia-
lects and languages. In the streets or in the countryside, it was easy to identify where
they lived and what their trade or station in life was just by their dress.
The way we dress has changed since then and the diversity by region, so rich at the
time, has faded away. It is now hard to tell apart the inhabitants of different conti-
nents, let alone different towns, regions, or countries. Perhaps we have traded cultural
diversity for a more varied personal life—certainly for a more varied and fast-paced
technological life.
At a time when it is hard to tell one computer book from another, Manning cele-
brates the inventiveness and initiative of the computer business with book covers
based on the rich diversity of regional life of two centuries ago, brought back to life by
Grasset de Saint-Sauveur’s pictures.
xxiii
xxiv ABOUT THE COVER ILLUSTRATION
Part 1
First steps
Welcome to our book! In these pages we are going to explore two exploding tech-
nologies: serverless computing and artificial intelligence. We will do this from an engi-
neering perspective. When we say an engineering perspective, we mean that this
book will provide you with a practical hands-on guide to get you up and running
with AI as a Service, without getting bogged down in a lot of theory.
We imagine that like most people, you have heard of these topics and will be
wondering why we’ve combined both of these seemingly disparate subjects into a
single book. As we will see throughout the following chapters, the combination of
these technologies has the potential to become the de facto standard for enterprise
3
4 CHAPTER 1 A tale of two technologies
Siebentes Kapitel.
Einleben ins Volkstum.
Massassi, Ende Juli 1906.