ebook img

Serverless Applications with Node.js: Using AWS Lambda and Claudia.js PDF

352 Pages·2019·8.48 MB·English
Save to my drive
Quick download
Download
Most books are stored in the elastic cloud where traffic is expensive. For this reason, we have a limit on daily download.

Preview Serverless Applications with Node.js: Using AWS Lambda and Claudia.js

WEB DEVELOPMENT/CLOUD Stojanovic´ Using AWS Lambda and Claudia.js Simovic´ Serverless Applications with Node.js Stojanovic´ ● Simovic´ See first page The benefi ts of cloud-hosted serverless web apps are undeniable: lower complexity, quicker time to market, and easier scalability than traditional, server-dependent “Teaches you how to get designs. And thanks to JavaScript support in AWS Lambda simple stuff done in AWS and powerful new serverless API tools like the Claudia.js Lambda quickly, without library, you can build and deploy serverless apps end to end trying to change the way you without learning a new language. structure or run projects.” Serverless Applications with Node.js teaches you to design and S —From the Foreword by e build serverless web apps on AWS using JavaScript, Node, and Gojko Adžić, Neuri Consulting r Claudia.js. You’ll master the basics of writing AWS Lambda v functions, along with core serverless patterns like API Gate- “A top-notch and hands-on e r way. Along the way, you’ll practice your new skills by building resource written by world- l a working chatbot and a voice assistant with Amazon Alexa. e renowned experts who will s You’ll also discover techniques for migrating existing apps to a get you up to speed in s serverless platform. no time with AWS Lambda A p using Claudia.js.” What’s Inside p —Valentin Crettaz, Consulthys l ● Authentication and database storage i c ● Asynchronous functions “One of the most a t ● Interesting real-world examples comprehensive books i o ● Developing serverless microservices published on the topic; n contains a wealth of s For web developers comfortable with JavaScript and Node.js. Slobodan Stojanovic´ resources that you will w Slobodan Stojanovic´ and Aleksandar Simovic´ are AWS Serverless not fi nd online.” i Aleksandar Simovic´ t Heroes and core contributors to the Claudia.js project. They —Damian Esteban, BetterPT h are also coauthors of Desolé, an open source serverless error- Foreword by Gojko Adžic´ N tracking tool, and the lead developers of Claudia Bot Builder. o d e . To download their free eBook in PDF, ePub, and Kindle formats, j s owners of this book should visit manning.com/books/serverless-applications-with-node-js M A N N I N G $44.99 / Can $59.99 [INCLUDING eBOOK] MANNING M A N N I N G Serverless Applications with Node.js SLOBODAN STOJANOVIC´ ALEKSANDAR SIMOVIC´ 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: [email protected] ©2019 by Manning Publications Co. All rights reserved. No part of this publication may be reproduced, stored in a retrieval system, or transmitted, in any form or by means electronic, mechanical, photocopying, or otherwise, without prior written permission of the publisher. 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-f ree 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. Manning Publications Co. Development editor: Toni Arritola 20 Baldwin Road Review editor: Ivan Martinovic´ PO Box 761 Project manager: Vincent Nordhaus Shelter Island, NY 11964 Copy editor: Darren Meiss Proofreader: Sarah Boyer Technical proofreader: Valentin Crettaz Typesetter: Happenstance Type-O-Rama Cover designer: Marija Tudor ISBN 9781617294723 Printed in the United States of America 1 2 3 4 5 6 7 8 9 10 – SP – 24 23 22 21 20 19 contents foreword ix preface xi acknowledgments xiii about this book xv about the authors xix about the cover illustration xx Part 1 Serverless pizzeria ......................................1 1 Introduction to serverless with Claudia 3 1.1 Servers and washing machines 4 1.2 The core concepts 5 1.3 How does serverless work? 6 1.4 Serverless in practice 6 Aunt Maria’s serverless pizzeria 7 ■ A common approach 7 ■ Serverless approach 9 1.5 Serverless infrastructure — AWS 9 1.6 What is Claudia, and how does it fit? 14 1.7 When and where you should use it 16 iii iivv contents 2 Building your first serverless API 19 2.1 Assembling pizza ingredients: building the API 19 Which pizza can I GET? 22 ■ Structuring your API 25 ■ POSTing an order 30 2.2 How Claudia deploys your API 34 2.3 Traffic control: How API Gateway works 35 2.4 When a serverless API is not the solution 36 2.5 Taste it! 37 Exercise 37 ■ Solution 37 3 Asynchronous work is easy, we Promise() 42 3.1 Storing the orders 43 3.2 Promising to deliver in less than 30 minutes! 48 3.3 Trying out your API 51 3.4 Getting orders from the database 55 3.5 Taste it! 57 Exercise 57 ■ Solution 58 4 Pizza delivery: Connecting an external service 62 4.1 Connecting to an external service 63 4.2 Connecting to the delivery API 64 The Some Like It Hot Delivery API 64 ■ Creating your first delivery request 65 4.3 Potential issues with async communication 71 Forgetting to return a promise 72 ■ Not passing the value from the promise 73 ■ Not wrapping the external service in a promise 73 ■ Timeout issues with long async operations 74 4.4 Taste it! 76 Exercise 76 ■ Solution 77 5 Houston, we have a problem! 80 5.1 Debugging a serverless app 81 5.2 Debugging your Lambda function 82 5.3 X-Ray your app 85 5.4 Taste it! 88 Exercise 88 ■ Solution 88 contents vv 6 Level up your API 90 6.1 Serverless authentication and authorization 91 6.2 Creating user and identity pools 94 Controlling API access with Cognito 97 6.3 Taste it! 101 Exercise 101 ■ Solution 101 7 Working with files 104 7.1 Storing static files in a serverless application 104 7.2 Generating thumbnails 108 Deploying your S3 function 114 7.3 Taste it! 116 Exercise 116 ■ Solution 116 7.4 End of part 1: Special exercise 118 Advanced task 118 Part 2 Let’s talk ...................................................121 8 When pizza is one message away: Chatbots 123 8.1 Pizza ordering beyond the browser 123 8.2 Hello from Facebook Messenger 124 8.3 What kinds of pizzas do you have? 128 8.4 Speeding up the deployment 130 8.5 Messenger templates 131 8.6 How does Claudia Bot Builder work? 134 8.7 Taste it! 136 Exercise 136 ■ Solution 136 9 Typing... Async and delayed responses 138 9.1 Making chatbots interactive 139 Tap to order: answering a postback 139 9.2 Making the chatbot structure more scalable 145 9.3 Connecting your chatbot to the DynamoDB database 149 9.4 Getting the user’s location from the chatbot 153 vvii contents 9.5 Scheduling a delivery 156 9.6 Small talk: Integrating simple NLP 161 9.7 Taste it! 163 Exercise 163 ■ Solution 163 ■ Advanced exercise 165 10 Jarvis, I mean Alexa, order me a pizza 166 10.1 Can’t talk right now: sending an SMS with Twilio 167 An SMS pizza list 169 ■ Ordering a pizza 170 10.2 Hey Alexa! 175 Preparing the skill 179 ■ Ordering pizza with Alexa 183 10.3 Taste it! 187 Exercise 187 ■ Solution 187 10.4 End of part 2: special exercise 188 Part 3 Next steps ..................................................189 11 Testing, Testing, 1, 2, 3 191 11.1 Testing server-hosted and serverless applications 191 11.2 How to approach testing serverless applications 193 11.3 Preparation 194 11.4 Unit tests 197 11.5 Mocking your serverless functions 201 11.6 Integration tests 207 11.7 Other types of automated testing 211 11.8 A step beyond: Writing testable serverless functions 212 11.9 Taste it! 216 Exercise 216 ■ Solution 217 12 Paying for pizza 219 12.1 Payment transactions 220 Implementing an online payment 221 12.2 Implementing your payment service 225 12.3 Could someone hack your payment service? 231 Standards 231 ■ Competence 232 12.4 Taste it! 232 Exercise 232 ■ Solution 233 contents vviiii 13 Migrating your existing Express.js app to AWS Lambda 235 13.1 Uncle Roberto’s taxi application 236 13.2 Running an Express.js application in AWS Lambda 236 Proxy integration 239 ■ How serverless-express works 239 13.3 Serving static content 240 13.4 Connecting to MongoDB 242 Using a managed MongoDB database with your serverless Express. js app 243 13.5 Limitations of serverless Express.js applications 248 13.6 Taste it! 249 Exercise 249 ■ Solution 249 14 Migrating to serverless 251 14.1 Analyzing your current serverless application 252 14.2 Migrating your existing application to serverless 252 14.3 Embrace the platform 256 Serving static files 256 ■ Storing state 256 ■ Logs 257 ■ Continuous integration 258 ■ Managing environments: production and development 259 ■ Sharing secrets 260 ■ VPC (Virtual Private Cloud) 262 14.4 Optimizing your application 263 Bundled or single-purpose functions 263 ■ Choosing the right memory size for your Lambda function 263 14.5 Facing the challenges 264 Handling timeouts 264 ■ Cold starts 265 ■ DDoS attacks 266 ■ Vendor lock-in 267 14.6 Taste it! 268 15 Real-world case studies 269 15.1 CodePen 270 Before serverless 270 ■ Serverless migration 271 ■ Cost of the infrastructure 273 ■ Testing and challenges 274 15.2 MindMup 275 Before serverless 275 ■ Serverless migration 276 ■ Cost of the infrastructure 278 ■ Testing, logs, and challenges 280 vviiiiii contents appendix A Installation and configuration 283 appendix B Facebook Messenger, Twilio, and Alexa configuration 289 appendix C Stripe and MongoDB setup 311 appendix D The pizza recipe 321 index 323

Description:
Serverless Applications with Node.js walks you through building serverless apps on AWS using JavaScript. Inside, you'll discover what Claudia.js brings to the table as you build and deploy a scalable event-based serverless application, based around a pizzeria that's fully integrated with AWS service
See more

The list of books you might like

Most books are stored in the elastic cloud where traffic is expensive. For this reason, we have a limit on daily download.