Serverless

April 2018

Global Azure Bootcamp

About Me

  • David Fekke
  • Chief Mobile Architect for Swyft Technology
  • Why is a Mobile developer giving an Azure presentation?
  • 20+ Years building Web Applications
  • .NET, Java, PHP, ColdFusion and Node.js
  • Commercial Pilot and Remote Pilot
  • Co-Organize JaxNode User Group
  • www.jaxnode.com

Servers

Australia Census Example 

  • Australia decided to go paperless in 2016
  • Load tested with millions of requests
  • 1000s of Aussies went to do their census online
  • Site was DDoS attacked
  • Down 40 hours
  • Census missed the deadline

Hosting Applications

  • Run locally
  • Deploy to Server (in a data center hopefully)
  • On Premise
  • Co-Location in rack space
  • Cloud Hosting (Rackspace, CenturyLink)
  • PAAS (AWS EC2, Azure, Bluemix)
  • Container hosting
  • Serverless (Lambda, Azure Functions)

Micro-Service apps

  • Composed of many services
  • Sometimes called micro-services
  • May have less than 200 lines of code
  • One function per service
  • Logging important!!!

Randrr's Cloud solution

  • AWS EC2
  • Deploying Docker and Kubernetes
  • Using Kafka and Cassandra for DBs
  • Microservices written in GO and Node.js
  • Node service was running in 50 MBs
  • Rewrote into GO, now 1 MB
  • No vendor lockin

Docker Issues

  • Still need to deploy VMs
  • VMs can be elastically deployed, but still need have some running all the time
  • Services running in Python or JavaScript become expensive
  • Services written in Java can have long warmup times

Lambda or Function apps

  • Don't need to manage infrastructure
  • Services can be written as simple functions
  • Deployed through Portal UI or through command line tools like the azure-cli
  • Available on Azure, AWS, IBM OpenWhisk and now Firebase functions

AWS Lambda

  • Written in JS, Java, Python, C# or Go
  • Bound to events or HTTP requests
  • 128 MB RAM Default per function
  • Monitor logging with CloudWatch

Azure Functions

  • Azure version of AWS Lambda
  • Similar model
  • NPM install modules through console
  • Use with Azure Logic Apps

Advantages of Serverless

  • Lowest Cost hosting
  • Simple development model
  • Simple deployment
  • Don't have to worry about load scheduling
  • Scales automagically

$0.20 per 1 million requests

Disadvantage of Serverless

  • Local development a challenge
  • No NPM Support (Azure has NPM)
  • Debugging threw logging

Executing Functions

  • Triggered off of events
  • HTTP endpoints
  • Schedule (cron)
  • fired on file uploads or queues

Ocean Disc example

 

  • Mobile app had to store reports
  • Upload to S3 storage
  • Process files based on upload event
  • Call REST based service
  • Accomplished threw AWS Lambda

We are going to need a bigger framework!

Serverless Framework

  • Formerly Called Jaws
  • Formerly AWS only
  • Build entire apps from Lambda/Functions
  • Organize functions
  • Local development and testing
  • resource management (APIs and Databases)
  • Multi-region development
  • Now on IBM OpenWhisk

Event Gateway

  • API Gateway
  • Cross cloud events
  • Platform agnostic
  • Extend through middleware

method signature

module.exports.hello = (context, data) => {
  const response = {
      message: 'Hello World!',
      input: data.paramName,
  };

  context.done(response);
};
module.exports.hello = (event, context, callback) => {
  const response = {
    statusCode: 200,
    body: JSON.stringify({
      message: 'Hello World!',
      input: event,
    }),
  };

  callback(null, response);
};

AWS Lambda method

Azure Environment Vars

# export Azure serverless keys
export azureSubId='########-####-####-####-46ac114fbfc4'
export azureServicePrincipalTenantId='########-####-####-####-bedeee9b4cf3'
export azureServicePrincipalClientId='http://azure-cli-2018-04-21-17-33-32'
export azureServicePrincipalPassword='########-####-####-####-79f2e198745f'

Install Serverless

  • Install Node.js
  • $ npm i -g serverless
  • Verify
  • $ sls -v

Serverless CLI

  • $ sls create -t azure-nodejs --path <path-to-app>
  • $ sls deploy
  • $ sls deploy --function functionName
  • $ sls invoke --function functionName
  • $ sls logs -f hello

Demo

Questions?

Resources

ServerlessAWS&Azure2.0

By David Fekke

ServerlessAWS&Azure2.0

These are the slides for the April 2017 Serverless presentation at Cloud Computing User Group

  • 1,142