42
GOING SERVERLESS DO SERVER-SIDE BETTER BY

Serverless presentation

Embed Size (px)

Citation preview

Page 1: Serverless presentation

GOING SERVERLESSDO SERVER-SIDE BETTER BY

Page 2: Serverless presentation

DO SERVER-SIDE BETTER BY GOING SERVERLESS

OVERVIEW - OUTLINE

▸ What’s all the hype about serverless architectures?

▸ Focus on Node.js, AWS Lambda, & Serverless Framework

▸ Discuss the advantages, disadvantages & limitations of a serverless architecture

Page 3: Serverless presentation

DO SERVER-SIDE BETTER BY GOING SERVERLESS

OVERVIEW - TAKEAWAYS

▸ General understanding of

▸ Serverless Architectures

▸ Node.js

▸ AWS Lambda

▸ Serverless Framework

▸ The value they provide

Page 4: Serverless presentation

DO SERVER-SIDE BETTER BY GOING SERVERLESS

ABOUT ME

▸ Jason Sich

▸ Software Developer at ClickFunnels.com

▸ Experience in JavaScript, Node.js, AWS, & Serverless Framework

▸ Not the best

Page 5: Serverless presentation

DO SERVER-SIDE BETTER BY GOING SERVERLESS

SERVERLESS ARCHITECTURE - SUCH HYPE

▸ News & Social Media (Hacker News, Lobsters, Twitter

▸ Conferences (Serverless Conf US/London)

▸ Libraries/Frameworks (Serverless Framework, Apex, Chalice, Zappa)

▸ AWS Flourish (Swagger for Lambda/API Gateway?)

Page 6: Serverless presentation

DO SERVER-SIDE BETTER BY GOING SERVERLESS

SERVERLESS ARCHITECTURE - WHAT IS IT?

▸ Functions as a Service

▸ “custom code that’s run in ephemeral containers” - Mike Roberts via martinfowler.com/articles/serverless.html

▸ Tightly coupled to providers infrastructure components

▸ e.g. API Gateway, S3

▸ Provides an easy integration point for providers

Page 7: Serverless presentation

DO SERVER-SIDE BETTER BY GOING SERVERLESS

SERVERLESS ARCHITECTURE - WHAT’S SO COOL ABOUT IT?

▸ Pay for what you need

▸ Easily scales

▸ Don’t have to manage servers!

▸ Easy deployment

Page 8: Serverless presentation

DO SERVER-SIDE BETTER BY GOING SERVERLESS

NODE.JS

▸ nodejs.org

Page 9: Serverless presentation

DO SERVER-SIDE BETTER BY GOING SERVERLESS

NODE.JS - WHAT IS IT?

▸ JavaScript runtime built on V8 engine

▸ Node.js is not exclusive, but is pervasive

▸ AWS Lambda

▸ Azure Functions

▸ Google Cloud Functions

▸ iron.io

Page 10: Serverless presentation

DO SERVER-SIDE BETTER BY GOING SERVERLESS

NODE.JS - WHAT’S COOL ABOUT IT?

▸ Event-driven, non-blocking I/O model

▸ Callbacks, Promises, Async/Await

▸ Typical use-cases for Serverless

▸ Scripted & Dynamic

▸ REPL

▸ Lots of existing libraries & tooling (aws-sdk)

Page 11: Serverless presentation

DO SERVER-SIDE BETTER BY GOING SERVERLESS

NODE.JS - USAGE

▸ JavaScript is Ubiquitous (Server/Web Client/Mobile)

▸ Big companies using Node.js

▸ Walmart

▸ Uber

▸ PayPal

▸ Netflix

Page 12: Serverless presentation

DO SERVER-SIDE BETTER BY GOING SERVERLESS

AWS LAMBDA - WHAT IS IT?

▸ Amazon’s AWS FaaS product

Page 13: Serverless presentation

DO SERVER-SIDE BETTER BY GOING SERVERLESS

AWS LAMBDA - FEATURES

▸ Pay by millisecond

▸ Horizontal Scaling

▸ Supports Node.js, Python, & Java (JVM Languages)

▸ No need to manage servers

▸ More flexible than PaaS

▸ Run Binaries, Temp Files, …

Page 14: Serverless presentation

DO SERVER-SIDE BETTER BY GOING SERVERLESS

AWS LAMBDA - THE WHOLE CLOUD (AT LEAST AMAZONS)

▸ API Gateway

▸ IoT

▸ Kinesis

▸ DynamoDB

▸ S3

▸ Cloud Watch

▸ Alexa

▸ CodeCommit

▸ SNS

▸ MORE…

Page 15: Serverless presentation

DO SERVER-SIDE BETTER BY GOING SERVERLESS

AWS LAMBDA - CONFIGURATION TOOLS

▸ AWS Web Console

▸ CloudFormation

▸ AWS CLI

▸ AWS SDK

Page 16: Serverless presentation

DO SERVER-SIDE BETTER BY GOING SERVERLESS

AWS LAMBDA - CONFIGURATION OPTIONS

▸ Runtime Support (Node, Java, Python)

▸ Memory

▸ 1536 MB max

▸ Timeout

▸ 5 minutes max

▸ Triggers

Page 17: Serverless presentation

DO SERVER-SIDE BETTER BY GOING SERVERLESS

AWS LAMBDA - CODE

▸ Inline coding using online editor

▸ S3 Zip

▸ Gotta package dependencies too

Page 18: Serverless presentation

DO SERVER-SIDE BETTER BY GOING SERVERLESS

AWS LAMBDA - DEPLOYMENT

▸ Qualifiers

▸ Aliases (Prod, Stage, Dev, whatever…)

▸ Versions

Page 19: Serverless presentation

DO SERVER-SIDE BETTER BY GOING SERVERLESS

AWS LAMBDA - INVOCATION

▸ AWS Web Console

▸ Event from Trigger Source

▸ AWS SDK

▸ Apps & other Lambdas

▸ API Gateway Endpoints

▸ Wizard!

Page 20: Serverless presentation

DO SERVER-SIDE BETTER BY GOING SERVERLESS

AWS LAMBDA - OBSERVATION

▸ Debugging

▸ ¯\_(ツ)_/¯

▸ Logging

▸ CloudWatch Logs

▸ Monitoring

▸ CloudWatch Metrics, Alarms & Dashboards

Page 21: Serverless presentation

DO SERVER-SIDE BETTER BY GOING SERVERLESS

SERVERLESS FRAMEWORK

▸ www.serverless.com

▸ CLI tool to create & manage Serverless Projects

Page 22: Serverless presentation

DO SERVER-SIDE BETTER BY GOING SERVERLESS

SERVERLESS FRAMEWORK - FUN FACTS

▸ Just hit v1.0

▸ $3 million in funding

▸ Source is Open

▸ Supports Node.js, Python, Java & More

▸ Other platforms than AWS coming soon (Serverless Platform is in beta)

Page 23: Serverless presentation

DO SERVER-SIDE BETTER BY GOING SERVERLESS

SERVERLESS FRAMEWORK - WHY?

▸ Helps organize & manage a serverless project

▸ Lambda creation, configuration & deployment

▸ AWS resource management via CloudFormation stacks

▸ Setup of Lambdas to Events & Resources

▸ Project structure by Services

Page 24: Serverless presentation

DO SERVER-SIDE BETTER BY GOING SERVERLESS

SERVERLESS FRAMEWORK - CONCEPTS

▸ Service

▸ Framework’s unit of organization (like a project)

▸ Defines the Functions along with the Events & Resources they use

Page 25: Serverless presentation

DO SERVER-SIDE BETTER BY GOING SERVERLESS

SERVERLESS FRAMEWORK - CONCEPTS

▸ Function

▸ AWS Lambda Function

▸ Can be independently deployed

▸ Should do a single thing (separate concerns)

Page 26: Serverless presentation

DO SERVER-SIDE BETTER BY GOING SERVERLESS

SERVERLESS FRAMEWORK - CONCEPTS

▸ Resources

▸ AWS infrastructure components

▸ DynamoDB Table

▸ S3 Buckets

▸ SNS Topics

▸ Anything defined by CloudFormation

Page 27: Serverless presentation

DO SERVER-SIDE BETTER BY GOING SERVERLESS

SERVERLESS FRAMEWORK - CONCEPTS

▸ Events

▸ Anything that triggers an AWS Lambda Function to execute

▸ ex: S3 Bucket Upload, CloudWatch Timer, …

Page 28: Serverless presentation

DO SERVER-SIDE BETTER BY GOING SERVERLESS

SERVERLESS FRAMEWORK - CLI

$ serverless create --template aws-nodejs --path foo

$ cd foo

$ serverless deploy -v

$ serverless deploy function -f bar

$ serverless invoke -f bar -p ./event.json -l

$ serverless logs -f bar -t

Page 29: Serverless presentation

DO SERVER-SIDE BETTER BY GOING SERVERLESS

SERVERLESS FRAMEWORK - CONFIGURATION

service: example

provider: name: aws stage: dev region: us-east-1 runtime: nodejs4.3 memorySize: 128 timeout: 30 iamRoleStatements: - Effect: "Allow" Action: - "lambda:InvokeFunction" - 's3:PutObject' - 's3:GetObject' Resource: “*"

Page 30: Serverless presentation

DO SERVER-SIDE BETTER BY GOING SERVERLESS

SERVERLESS FRAMEWORK - CONFIGURATION

functions: echo: handler: foo/index.handler events: - stream: arn:aws:dynamodb:region:xxx:table/foo/stream/…

resources: Resources: fooTable: Type: AWS::DynamoDB::Table Properties: TableName: fooTable KeySchema: - AttributeName: baz

Page 31: Serverless presentation

DO SERVER-SIDE BETTER BY GOING SERVERLESS

ALL TOGETHER NOW - THE GOOD

▸ Node.js

▸ Event-driven I/O model

▸ Ubiquitous

▸ Prevalent

Page 32: Serverless presentation

DO SERVER-SIDE BETTER BY GOING SERVERLESS

ALL TOGETHER NOW - THE GOOD

▸ AWS Lambda

▸ Pay per millisecond

▸ No servers to manage

▸ Fairly flexible (binaries, temp files, …)

Page 33: Serverless presentation

DO SERVER-SIDE BETTER BY GOING SERVERLESS

ALL TOGETHER NOW - THE GOOD

▸ Serverless Framework

▸ Serverless management from the command line

▸ Gives structure/conventions to FaaS project

▸ Stays out of your way during coding

Page 34: Serverless presentation

DO SERVER-SIDE BETTER BY GOING SERVERLESS

ALL TOGETHER NOW - THE BAD

▸ Node.js

▸ Language & ecosystem are evolving quickly

▸ Async first

▸ Lacking standard library

Page 35: Serverless presentation

DO SERVER-SIDE BETTER BY GOING SERVERLESS

ALL TOGETHER NOW - THE BAD

▸ AWS lambda limits

Page 36: Serverless presentation

DO SERVER-SIDE BETTER BY GOING SERVERLESS

ALL TOGETHER NOW - THE BAD

▸ AWS lambda limits

Page 37: Serverless presentation

DO SERVER-SIDE BETTER BY GOING SERVERLESS

ALL TOGETHER NOW - THE BAD

▸ AWS lambda limits

Page 38: Serverless presentation

DO SERVER-SIDE BETTER BY GOING SERVERLESS

ALL TOGETHER NOW - THE BAD

▸ AWS lambda

▸ Node v4.3

▸ Cold Start Time

▸ Response Times

▸ API Gateway, CloudFront Distribution, Lambda

▸ AWS Web Console is not fun to use

Page 39: Serverless presentation

DO SERVER-SIDE BETTER BY GOING SERVERLESS

ALL TOGETHER NOW - THE BAD

▸ AWS Lambda

▸ Debugging can be hard

▸ Statelessness

▸ Resource usage spikes

▸ Vendored dependencies

Page 40: Serverless presentation

DO SERVER-SIDE BETTER BY GOING SERVERLESS

ALL TOGETHER NOW - THE BAD

▸ Serverless Framework

▸ Evolving quickly JAWS -> SF v0.5 -> SF v1.0

▸ May not play well with other infrastructure tools

▸ New, needs maturity

Page 41: Serverless presentation

DO SERVER-SIDE BETTER BY GOING SERVERLESS

MORAL OF THE STORY

▸ Great if you are planning to AWS

▸ Can be cost effective vs running & managing a server

▸ Awesome for event handling

Page 42: Serverless presentation

DO SERVER-SIDE BETTER BY GOING SERVERLESS

THE END

▸ Questions?

▸ Twitter: @jasich, @grdevnight

▸ Slides will get posted there