View
261
Download
1
Category
Preview:
Citation preview
GOING SERVERLESSDO SERVER-SIDE BETTER BY
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
DO SERVER-SIDE BETTER BY GOING SERVERLESS
OVERVIEW - TAKEAWAYS
▸ General understanding of
▸ Serverless Architectures
▸ Node.js
▸ AWS Lambda
▸ Serverless Framework
▸ The value they provide
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
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?)
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
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
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
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)
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
DO SERVER-SIDE BETTER BY GOING SERVERLESS
AWS LAMBDA - WHAT IS IT?
▸ Amazon’s AWS FaaS product
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, …
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…
DO SERVER-SIDE BETTER BY GOING SERVERLESS
AWS LAMBDA - CONFIGURATION TOOLS
▸ AWS Web Console
▸ CloudFormation
▸ AWS CLI
▸ AWS SDK
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
DO SERVER-SIDE BETTER BY GOING SERVERLESS
AWS LAMBDA - CODE
▸ Inline coding using online editor
▸ S3 Zip
▸ Gotta package dependencies too
DO SERVER-SIDE BETTER BY GOING SERVERLESS
AWS LAMBDA - DEPLOYMENT
▸ Qualifiers
▸ Aliases (Prod, Stage, Dev, whatever…)
▸ Versions
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!
DO SERVER-SIDE BETTER BY GOING SERVERLESS
AWS LAMBDA - OBSERVATION
▸ Debugging
▸ ¯\_(ツ)_/¯
▸ Logging
▸ CloudWatch Logs
▸ Monitoring
▸ CloudWatch Metrics, Alarms & Dashboards
DO SERVER-SIDE BETTER BY GOING SERVERLESS
SERVERLESS FRAMEWORK
▸ www.serverless.com
▸ CLI tool to create & manage Serverless Projects
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)
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
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
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)
DO SERVER-SIDE BETTER BY GOING SERVERLESS
SERVERLESS FRAMEWORK - CONCEPTS
▸ Resources
▸ AWS infrastructure components
▸ DynamoDB Table
▸ S3 Buckets
▸ SNS Topics
▸ Anything defined by CloudFormation
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, …
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
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: “*"
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
DO SERVER-SIDE BETTER BY GOING SERVERLESS
ALL TOGETHER NOW - THE GOOD
▸ Node.js
▸ Event-driven I/O model
▸ Ubiquitous
▸ Prevalent
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, …)
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
DO SERVER-SIDE BETTER BY GOING SERVERLESS
ALL TOGETHER NOW - THE BAD
▸ Node.js
▸ Language & ecosystem are evolving quickly
▸ Async first
▸ Lacking standard library
DO SERVER-SIDE BETTER BY GOING SERVERLESS
ALL TOGETHER NOW - THE BAD
▸ AWS lambda limits
DO SERVER-SIDE BETTER BY GOING SERVERLESS
ALL TOGETHER NOW - THE BAD
▸ AWS lambda limits
DO SERVER-SIDE BETTER BY GOING SERVERLESS
ALL TOGETHER NOW - THE BAD
▸ AWS lambda limits
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
DO SERVER-SIDE BETTER BY GOING SERVERLESS
ALL TOGETHER NOW - THE BAD
▸ AWS Lambda
▸ Debugging can be hard
▸ Statelessness
▸ Resource usage spikes
▸ Vendored dependencies
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
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
DO SERVER-SIDE BETTER BY GOING SERVERLESS
THE END
▸ Questions?
▸ Twitter: @jasich, @grdevnight
▸ Slides will get posted there
Recommended