Serverless Apps with Node.js MEAP V06 - Chapter 1 · PDF fileNode.js: Using AWS Lambda and...

Click here to load reader

  • date post

    09-Sep-2018
  • Category

    Documents

  • view

    220
  • download

    0

Embed Size (px)

Transcript of Serverless Apps with Node.js MEAP V06 - Chapter 1 · PDF fileNode.js: Using AWS Lambda and...

  • MEAPEditionManningEarlyAccessProgram

    ServerlessApplicationswithNode.jsUsingAWSLambdaandClaudia.js

    Version6

    Copyright2018ManningPublications

    FormoreinformationonthisandotherManningtitlesgotowww.manning.com

    Manning Publications Co. We welcome reader comments about anything in the manuscript - other than typos and other simple mistakes. These will be cleaned up during production of the book by copyeditors and proofreaders.

    https://forums.manning.com/forums/serverless-applications-with-nodejs

    http://www.manning.comhttps://forums.manning.com/forums/serverless-applications-with-nodejs

  • welcome Thank you for purchasing the MEAP edition of Serverless Applications with Node.js: Using AWS Lambda and Claudia.js.

    Serverless is an extremely hot topic. Started by Amazon, and closely followed by Google and Microsoft, it has a potential to revolutionize the way we think of application development and deployment. Its abstraction of servers has a huge effect on the application development lifecycle and may potentially remove the need for big DevOps teams.

    Many of the available resources on serverless are focusing on its small or specific portions, so its hard to gain even a glimpse of a complete serverless application. Thats the main goal of our book to give you a clean and simple overview how a serverless app should look like, explain the underlying technology, and present good practices along the way.

    Serverless is a different approach to application development and deployment with a fast design-to-deployment time, without renting or buying servers, setting up and managing internal resources and databases. Along with Claudia and its single command deployment, developing highly scalable and reliable applications becomes a breeze.

    To present the new concepts in a convenient way, this book will lead you through an implementation of an API for a local pizzeria. You will encounter many issues youd usually face when building real-world applications. This example will introduce several interesting characters with many different requests, and situations which will lead you from a simple order handling to building a full-featured serverless Pizza API and accepting orders via voice commands. All in a step-by-step approach.

    Our book is divided into three parts. The main goal of Part 1 is to teach you the foundation of serverless. You will

    learn how to develop a serverless API and understand the underlying concepts. You will also learn how serverless impacts your current application development, and how do needed application services, such as storage and authorization, work in a serverless way.

    Manning Publications Co. We welcome reader comments about anything in the manuscript - other than typos and other simple mistakes. These will be cleaned up during production of the book by copyeditors and proofreaders.

    https://forums.manning.com/forums/serverless-applications-with-nodejs

    https://forums.manning.com/forums/serverless-applications-with-nodejs

  • Part 2 upgrades your previous work with some of the trendy technologies, such as building a Facebook Messenger chatbot to accept pizza orders, and Amazon Alexa skill for ordering pizzas with a single voice command.

    Because the real-world applications often goes beyond a simple API, we reserved Part 3 for more advanced topics. This part will teach you how to test your serverless applications and how to integrate a payment processor, as highly sought and challenging topics. It will also 1 show you good practices in structuring and organizing your application and help you to migrate the existing application to serverless, step-by-step.

    We hope youll enjoy this book and that it will occupy an important place on your digital, and later physical, bookshelf.

    Our goal is to make this book an essential guide to serverless applications with Node.js. We encourage you (and greatly appreciate) to post any kind of questions, comments or suggestions about the content in the books forum. All of your feedback will bring us together towards the goal.

    Slobodan Stojanovi and Aleksandar Simovi

    Manning Publications Co. We welcome reader comments about anything in the manuscript - other than typos and other simple mistakes. These will be cleaned up during production of the book by copyeditors and proofreaders.

    https://forums.manning.com/forums/serverless-applications-with-nodejs

    https://forums.manning.com/forums/serverless-applications-with-nodejs

  • brief contents PART 1: SERVERLESS PIZZERIA

    1 Introduction to serverless with Claudia 2 Building your first serverless API 3 Asynchronous work is easy, we Promise() 4 Pizza delivery: connecting an external service 5 Houston, we have a problem! 6 Level up your API 7 Working with files

    PART 2: LET'S TALK 8 When pizza is one message away: Chatbots 9 Typing Async and delayed responses 10 Jarvis, I mean Alexa, order me a pizza

    PART 3: NEXT STEPS 11 Testing, testing, 1, 2, 3 12 Paying for pizza 13 Migrating your existing Express.js app to AWS Lambda 14 Migrating to serverless 15 Real-world case studies

    APPENDIXES A Installation and configuration B Facebook messenger, Twilio, and Alexa configuration C Stripe and MongoDB setup D The pizza recipe

    Manning Publications Co. We welcome reader comments about anything in the manuscript - other than typos and other simple mistakes. These will be cleaned up during production of the book by copyeditors and proofreaders.

    https://forums.manning.com/forums/serverless-applications-with-nodejs

    https://forums.manning.com/forums/serverless-applications-with-nodejs

  • Part 1

    Aunt Maria is a strong-willed person. For more than three decades, she has been managing her pizzeria, a gathering place for many generations in the neighborhood: Lots of people spent time there with their families, laughed, and even went on romantic dates. But recently, her pizzeria has seen some rough times. She told you shes seeing fewer and fewer customers. The rise in technology caused her customers to prefer ordering online via websites or their phones from competitors pizzerias.

    Her pizzeria already has a website but needs a back-end application to process and store information on pizzas and orders.

    In the first part of this book, your goal will be to help Aunt Maria to catch up with the competition by building a serverless API for her. But because youre still new to serverless development, youll first learn what serverless is and how it can help you to build Pizzeria API (chapter 1). Then youll continue by adding routes to your API and deploying it to AWS Lambda using Claudia (chapter 2). To persist and deliver all orders, youll connect your new API to the DynamoDB table (chapter 3) and communicate with a third-party service: Some Like It Hot delivery API (chapter 4).

    During the development, youll face certain problems and learn how to debug the serverless application (chapter 5).

    To make the API fully functional, youll need to learn how to authenticate and authorize users (chapter 6) and keep and manipulate pizza images (chapter 7).

    Serverless Pizzeria

    Manning Publications Co. We welcome reader comments about anything in the manuscript - other than typos and other simple mistakes. These will be cleaned up during production of the book by copyeditors and proofreaders.

    https://forums.manning.com/forums/serverless-applications-with-nodejs

    1

    https://forums.manning.com/forums/serverless-applications-with-nodejs

  • 1 This chapter covers: What serverless is The core concepts The difference between serverless and hosted web applications How Claudia fits Why to use serverless

    Serverless is a method of deploying and running applications on cloud infrastructure, on a pay-per-use basis and without renting or buying servers. Instead of you, the serverless platform provider is responsible for capacity planning, scaling, balancing, and monitoring; the provider is also able to treat your applications as functions.

    Wait, no servers? Seems like a new buzzword, a hipster cloud trend promising to revolutionize your life for the better.

    This book will explain what serverless is, what problems it solves, and where it does or doesnt fit into your application development process without fanboyishly showing off and selling serverless like some trendy cloud cult that everyone needs to follow. It will do that with a pragmatic approach, explaining the concepts by teaching you how to build reliable and scalable serverless applications with Node.js and Claudia.js, while saving time and resources.

    This chapter focuses on the concepts of serverless: what it is, why it matters, and how it compares to server-hosted web application development. Your main goal for this chapter is to gain a good understanding of basic serverless concepts and build a good foundation.

    Introduction to serverless with Claudia

    Manning Publications Co. We welcome reader comments about anything in the manuscript - other than typos and other simple mistakes. These will be cleaned up during production of the book by copyeditors and proofreaders.

    https://forums.manning.com/forums/serverless-applications-with-nodejs

    2

    https://forums.manning.com/forums/serverless-applications-with-nodejs

  • 1.1 Servers and washing machines To understand serverless, consider for a moment washing machines. This might sound like a crazy place to start, but owning a server nowadays is very similar to owning a washing machine. Everybody needs to clean their clothes, and the most logical solution seems to be buying a washing machine. But most of the time th