Developing Serverless Applications a Practical Introduction with Apache Openwhisk

Developing Serverless Applications a Practical Introduction with Apache Openwhisk

Develop apps faster. Go serverless without vendor lock-in. Control costs, autoscale, and integrate systems across clouds. | IBM Cloud Functions It's simple. Pay only for exact times your actions run, down to one-tenth of a second: no memory, no cost. Based on Apache OpenWhisk, IBM Cloud Functions Trigger your actions from events in your favorite provides an ecosystem in which developers cloud services, or directly from your apps via can share and use code across environments. REST APIs. Run actions thousands of times in a second or Develop actions in your favorite language: Java, once a week. Action instances scale to meet exact Swift, JS/Node.JS, PHP, Python. You can also use demand, then disappear. any code in a Docker container as an action. Focus on building and running apps, not maintaining servers Quickly bind AI services to your action sequences Choose a cloud environment with open source tools IBM Cloud Functions https://ibm.co/CloudFunctions © Copyright IBM Corporation 2017. The IBM logo and ibm.com are trademarks of International Business Machines Corp., registered in many jurisdictions worldwide. Other product and service names might be trademarks of IBM or other companies. A current list of IBM trademarks is available on the Web at “Copyright and trademark information” at www.ibm.com/legal/us/en/copytrade.shtml. Developing Serverless Applications A Practical Introduction with Apache OpenWhisk Raymond Camden Beijing Boston Farnham Sebastopol Tokyo Developing Serverless Applications by Raymond Camden Copyright © 2018 O’Reilly Media, Inc. All rights reserved. Printed in the United States of America. Published by O’Reilly Media, Inc., 1005 Gravenstein Highway North, Sebastopol, CA 95472. O’Reilly books may be purchased for educational, business, or sales promotional use. Online editions are also available for most titles (http://oreilly.com/safari). For more information, contact our corporate/institutional sales department: 800-998-9938 or [email protected]. Editors: Brian Foster and Virginia Wil‐ Cover Designer: Karen Montgomery son Illustrator: Rebecca Demarest Production Editor: Shiny Kalapurakkel Tech Reviewers: Mike Roberts, John Cha‐ Copyeditor: Matthew Burgoyne pin, Brian Rinaldi, Jess Males Interior Designer: David Futato October 2017: First Edition Revision History for the First Edition 2017-10-06: First Release The O’Reilly logo is a registered trademark of O’Reilly Media, Inc. Developing Serv‐ erless Applications, the cover image, and related trade dress are trademarks of O’Reilly Media, Inc. While the publisher and the author have used good faith efforts to ensure that the information and instructions contained in this work are accurate, the publisher and the author disclaim all responsibility for errors or omissions, including without limi‐ tation responsibility for damages resulting from the use of or reliance on this work. Use of the information and instructions contained in this work is at your own risk. If any code samples or other technology this work contains or describes is subject to open source licenses or the intellectual property rights of others, it is your responsi‐ bility to ensure that your use thereof complies with such licenses and/or rights. 978-1-491-99622-5 [LSI] Table of Contents 1. Introduction. 1 What Is Serverless? 1 Serverless Use Cases 2 Who Is This Book For? 3 Getting the Source 4 2. OpenWhisk Basics. 5 Introduction to Apache OpenWhisk 5 OpenWhisk on IBM Cloud (Bluemix) 6 Registering for IBM Cloud (Bluemix) 7 Getting the OpenWhisk CLI 9 3. Working with Actions. 13 The Fundamentals of OpenWhisk Actions 13 Options for OpenWhisk Actions 14 Rules for JavaScript Actions 15 Your First Action 16 Running Your Action 19 Working with Arguments 23 Asynchronous Actions 25 4. Using OpenWhisk Actions. 29 Authenticated REST API 29 Web Actions 31 API Management 36 iii 5. Building Sequences. 49 Creating Sequences 51 6. Working with Packages. 55 Creating and Managing Packages 56 Using Bluemix Packages 61 7. Using Triggers and Rules . 63 What are Triggers? 63 What are Rules? 64 Feeds and OpenWhisk Supplied Triggers 65 8. Going Further with OpenWhisk. 67 Asking Questions 67 Additional Reading 68 Participating 68 Everything Else 68 iv | Table of Contents CHAPTER 1 Introduction This book aims to help you enter the exciting new world of server‐ less development. By the end of the book, you’ll know how to use Apache OpenWhisk to write serverless functions and how to call them from applications. You’ll see how to create powerful new serv‐ ices by combining existing actions into sequences, as well as how they can be automated with triggers. What Is Serverless? The technical industry is rife with terms that sometimes bear little to no resemblance to what they supposedly represent. Serverless is the latest example of this. Many people object to the term because servers are always involved with anything hosted on the internet. Of course, if we can get over the fact that the cloud isn’t literally a few thousand feet over our heads, we can move to accept this new term as well. It’s best to think of serverless as not the lack of servers, but the lack of server management. Serverless is best described as the ability to deploy your apps without worrying about provisioning and manag‐ ing a server. This could be seen as a natural outgrowth of the cloud and virtual servers. Virtual servers greatly improved our lives by allowing developers to add (and remove) servers with the click of a button. Suddenly, you didn’t have to ask permission, or wait around, to put your applica‐ tion online. As awesome as this was, it came with some drawbacks. 1 Servers require maintenance. They have to be locked down. They have to be set up with the appropriate amount of RAM and disk space. They also have to be running to actually do anything. While that’s obvious, it’s easy to forget that you’re paying for a server to run all day, every day, even when the app in question isn’t actually being used. This is where serverless truly shines. Instead of provisioning an entire server, you can take the logic that comprises your application and simply deploy it as is. You can think of this as “Function as a Service.” This greatly simplifies the process of getting what you need online and ready to be used. You no longer need to worry about set‐ ting up a web server or figuring out how to route a particular request to a particular piece of logic. Instead, you deploy that logic (a function) and the serverless provider handles everything else. Best of all, your costs can go way down. Instead of a server running constantly, the serverless platform fires up your code when reques‐ ted. When your code isn’t being used, nothing is running. You pay for your usage and nothing more! While every platform has it’s own pricing model, your costs in general will be far less. If you think this sounds compelling, you aren’t alone. Many of the biggest tech companies now offer serverless as a product offering. Amazon led the way with AWS Lambda, the oldest and most mature serverless platform. Google has Cloud Functions, and Microsoft has Azure Functions. In this book, we’ll be focusing on IBM Cloud Functions, a serverless solution created by IBM based on Apache OpenWhisk. Serverless Use Cases It is (most likely) simpler to work with serverless and certainly cheaper, but what are some use cases where serverless shines? Here are just a few examples. APIs for CRUD CRUD, or Create/Read/Update/Delete, refers to how people typically work with content. Given you have a set of data, your app may need to perform CRUD as part of its functionality. In the past, APIs for this would be built in a server-side application and handle passing calls back and forth between a frontend and a backend storage system. Serverless is great for these simple 2 | Chapter 1: Introduction proxies by reducing the amount of overhead you need to sup‐ port the APIs. Rewriting APIs One of the cooler things you can do with serverless is build an API that rewrites another API. Imagine an API that only returns XML. You could use serverless to build a proxy that transforms it to JSON. Imagine an API that returns useful infor‐ mation, but also a lot of data your clients don’t need. You could use your API to simply remove the unwanted data. Slow background work Anything that is slow (comparatively) will typically be handled by a process running in the background on a scheduled basis. Examples of this include image processing (such as optimizing and resizing), log processing, or simply handling uploaded files. Serverless is a great way to build these background utilities. Who Is This Book For? This book is for the developer who works on the backend, creating services to support frontend clients. Those clients could be basic websites or more modern progressive web apps. They can also be mobile apps written using hybrid technologies like Apache Cordova, or fully native apps written in Java or Swift. This book is for anyone who has had to set up an environment, a web server, and other tools just to build an API, and would love to see a much simpler way of standing up services. Apache OpenWhisk supports multiple languages, but this book focuses on JavaScript for working with serverless. You do not need to be a JavaScript expert in order to work with the examples. If you know nothing at all about JavaScript and want to quickly get up to speed, or just want to brush up on your knowledge, I highly recom‐ mend bookmarking the MDN Web Docs, seen in Figure 1-1.

View Full Text

Details

  • File Type
    pdf
  • Upload Time
    -
  • Content Languages
    English
  • Upload User
    Anonymous/Not logged-in
  • File Pages
    77 Page
  • File Size
    -

Download

Channel Download Status
Express Download Enable

Copyright

We respect the copyrights and intellectual property rights of all users. All uploaded documents are either original works of the uploader or authorized works of the rightful owners.

  • Not to be reproduced or distributed without explicit permission.
  • Not used for commercial purposes outside of approved use cases.
  • Not used to infringe on the rights of the original creators.
  • If you believe any content infringes your copyright, please contact us immediately.

Support

For help with questions, suggestions, or problems, please contact us