Introduction to Serverless

(and our group)

 

... featuring AWS

About Me

1st Career

About Me

2nd Career

About our group

Vendor Neutral

1st Tuesday of the month

(except January 2019: is 2nd Tuesday)

5:30pm - 8:30pm

 

Richmond Heights Community Center

"Dale" Room

 

Free and open to the public!

https://www.meetup.com/stl-serverless/events/254589340/

Coming in 2018

  • November 6th - Serverless Security

    • Featuring Azure

  • December 4th - Serverless Testing

    • Featuring Google Cloud

Coming in 2019

  • Serverless frameworks

  • Special guest speakers

  • Hands-on workshops

  • Serverless coding contests

  • Networking and Social Events

  • more...

Help Wanted!

Looking for a Backup Co-organizer

Speakers Wanted

Meeting Sponsors Wanted

Tell about your company while we enjoy your refreshments

Other Help Wanted

Overview

  • What is serverless?
  • Advantages & Disadvantages

What is serverless?

Let's start with what it isn't

Serverless does not mean, "No servers"

Serverless computing allows you to build and run applications and services without thinking about servers. Serverless applications don't require you to provision, scale, and manage any servers. You can build them for nearly any type of application or backend service, and everything required to run and scale your application with high availability is handled for you.

Amazon Web Services (AWS):

https://aws.amazon.com/serverless/

Serverless computing is the abstraction of servers, infrastructure, and operating systems. When you build serverless apps you don’t need to provision and manage any servers, so you can take your mind off infrastructure concerns. Serverless computing is driven by the reaction to events and triggers happening in near-real-time—in the cloud. As a fully managed service, server management and capacity planning are invisible to the developer and billing is based just on resources consumed or the actual time your code is running.

Microsoft Azure:

https://azure.microsoft.com/en-us/overview/serverless-computing/

Serverless lets you write and deploy code without the hassle of managing the underlying infrastructure. It enhances developer productivity by helping focus on what matters the most — building great applications and abstracting away the rest. Zero server management, no upfront provisioning, auto-scaling to meet traffic demands, and paying only for the resources used are just some of the benefits of serverless computing.

Google Cloud Platform:

https://cloud.google.com/serverless/​

Serverless lets you* think about servers less.

In summary...

*Someone else is still thinking about the servers

Path to Serverless

Path to Serverless

Bare Metal

Virtual Machines

IaaS

PaaS

CaaS

FaaS

Value Line

Serverless includes...

Storage

Queues

Notifications

API Gateways

Functions

Monitoring & Logging

and much, much more... Fargate, Aurora Serverless, etc.

Advantages of Serverless

  • Development simplicity
  • Zero provisioning or management
  • Scale up based on events
  • Scale to zero
  • Highly available
  • Usage-based billing

Development Simplicity

Over time, monolith applications become increasingly difficult to understand, maintain and enhance

Development Simplicity

We started breaking up monoliths into microservices along bounded context seams

Development Simplicity

We now have the ability to break up microservices into stand alone functions which can be deployed and scaled independently 

Authentication

Lookup User

Gen Token

Verify Token

Refresh Token

Development Simplicity

A function that does just one thing is far easier to maintain, enhance, or rewrite entirely

Authentication

package example;

import com.amazonaws.services.lambda.runtime.Context; 
import com.amazonaws.services.lambda.runtime.RequestHandler;
import ...

public class GenerateToken implements RequestHandler<User, String> {

    String handleRequest(User authenticatedUser, Context context) {
        return generateToken(authenticatedUser);
    }

    private String generateToken(User authenticatedUser) {
        // create JWT with claims
    }

}

Zero Server Management

Scale up based on events

[ { "item": 1} ]

Item(1)

Scale up based on events

[ { "item": 1},

...

{"item" : 3} ]

Item(1)

Item(2)

Item(3)

AWS Lambda Event Sources

  • Amazon S3
  • Amazon DynamoDB
  • Amazon Kinesis Data Streams
  • Amazon Simple Notification Service
  • Amazon Simple Email Service
  • Amazon Simple Queue Service
  • Amazon Cognito
  • AWS CloudFormation
  • Amazon CloudWatch Logs
  • Amazon CloudWatch Events
  • AWS CodeCommit
  • Scheduled Events (powered by Amazon CloudWatch Events)
  • AWS Config
  • Amazon Alexa
  • Amazon Lex
  • Amazon API Gateway
  • AWS IoT Button
  • Amazon CloudFront
  • Amazon Kinesis Data Firehose
  • Other Event Sources: Invoking a Lambda Function On Demand

Scale to Zero

  • Zero or few customers
    • New Project
    • Startup
  • Development 7am - 7pm
  • Periodic loads
    • Evening batch runs
  • Occasional, sporadic loads
    • "Forgot password"
    • CI Build
    • Testing

Highly Available

Usage-based Billing

  • Zero or few customers
    • No charge until customers start using it
  • High loads 7am - 7pm
    • No charge after 7pm
  • Periodic loads
    • No charge until batch job runs
  • Occasional, sporadic loads
    • No charge until load appears

However...

... and there's always a however

Disadvantages of Serverless

  • Development complexity
  • Testing complexity
  • Deployment complexity
  • Cold start performance

These topics and more will form the basis for future talks

Development Complexity

  • With a monolith, we can have
    • One project
    • One build pipeline
    • One deployment artifact
    • One place to look for a problem
  • With microservices, we compound this
  • With serverless, it's even more complex

Testing Complexity

  • Unit testing functions is easy
  • Integration testing is harder
  • We often depend on cloud provider services
  • Frameworks can help
    • Localstack: https://github.com/localstack/localstack
    • AWS SAM Local
  • We may need to accept integration testing must be done on the cloud

Deployment Complexity

This...

Deployment Complexity

Becomes this...

Cold Start Performance

  • Cold start time is the time between when a request is received and the handler starts processing the request
  • Different languages and frameworks have different cold start penalties
  • Available memory dramatically affects cold start performance

Cold Start Performance

https://blog.newrelic.com/engineering/lambda-functions-xray-traces-custom-serverless-metrics/

Cold Start Performance

https://read.acloud.guru/does-coding-language-memory-or-package-size-affect-cold-starts-of-aws-lambda-a15e26d12c76

How long will it stay warm?

https://read.acloud.guru/how-long-does-aws-lambda-keep-your-idle-functions-around-before-a-cold-start-bf715d3b810

Serverless Providers

Many others

Serverless Runtimes

Serverless Architectural Patterns

  • Request-Response
  • Event-Driven

Request-Response

request

trigger

return

response

API Gateway

(29 sec limit)

Lambda

(5 min limit)

Event-Driven

event

trigger

Lambda

Add 1080p video to

S3 bucket

Transcode

to 720p

Save to 720p bucket

event

SNS

trigger

Productionizing Serverless

  • With monolith, we deploy artifact into an environment we control
    • VM
    • Container
  • With Serverless, we deploy into a provider  environment
    • Same environment for Development, Testing and Production
    • We could deploy into our own VPC, but shouldn't
  • How do we differentiate?

Productionizing Serverless

  • With AWS, we use Lambda versions and aliases
  • A Lambda version is immutable
    • No code change allowed
    • No configuration information can be changed
    • If we change the code or config, we make a new version
    • The latest version can be referenced as $LATEST
  • An alias, points to a specific version
    • Development -> $LATEST
    • Test -> 1.2.0
    • Production -> 1.1.5

Productionizing Serverless

https://docs.aws.amazon.com/lambda/latest/dg/aliases-intro.html

Productionizing Serverless

  • Other productionizing topics for future talks
    • Logging
    • Monitoring
    • Tracing
    • Debugging
    • Security
    • ???

Resources

  • https://aws.amazon.com/serverless/
  • https://azure.microsoft.com/en-us/overview/serverless-computing/
  • https://cloud.google.com/serverless/
  • A Cloud Guru Blog - https://read.acloud.guru/
  • Me
    • jackfrosch@stlserverless.com
    • LinkedIn: in/jackfrosch
    • Twitter @jackfrosch

Next Meeting:

Developing Serverless

featuring Azure

Questions?

Demo / Lab

Create an AWS Lambda with

API Gateway HTTP Trigger

Function code below.

Video screencast on this coming soon.

Our code

exports.handler = (event, context, callback) => {
    console.log(event);
    
    const parms = event.queryStringParameters;
    const min = parms ? parseInt(parms.min) : 1;    // parms come in as strings
    const max = parms ? parseInt(parms.max) : 100;
    
    const randomVal = Math.floor(Math.random() * (max - min + 1) + min);
    console.log("random number", randomVal);
    
    console.log("min", min);
    console.log("max", max);
    
    const result = {
        min: min,
        max: max,
        randomVal: randomVal 
    }
    
    const response = {
        statusCode: 200,
        body: JSON.stringify(result)
    };
    
    callback(null, response);
};