Serverless Deployment with AWS

Andrew Lombardi / @kinabalu

Mystic Coders, LLC

About Me

About Me

About Me

18 Years in Business

10 Years @ Java2Days

Published Author

Software Consultants

Invented the Internet

 

To our success!

WebSocket Book


http://bit.ly/websocketbook

Incomplete History of Deployment

Rack Servers

Traditional IT

PaaS

Serverless / FaaS

What is Serverless?

  • No server / instance management
  • Auto Scaling Provision based on load
  • Costs measured on usage
  • High availability

Service Models

Backend as a Service (BaaS)

Function as a Service (FaaS)

FaaS

Event driven

Runs user functions

Auto scaled and provisioned

Precise costs

Stateless

FaaS vs PaaS

In a PaaS environment, scaling is still your problem, with FaaS it's handled.

Supported Languages / Platforms

  • Node.js
  • Python (3.6, 3.7, 2.7)
  • Java 8
  • C# (.NET Core)
  • Go

Events / Triggers

S3 DynamoDB Kinesis Data Streams SNS
SES SQS Cognito CloudFormation
CloudWatch Logs CloudWatch Events CodeCommit Scheduled Events
AWS Config Alexa Lex API Gateway
AWS IoT Button CloudFront Kinesis Data Firehose Invoke Lambda Function On Demand

Lambda Behind the Scenes

  • $ per GB/sec, 100ms increments
  • Containers on EC2
  • Created on demand
  • Reaped when idle, old or obsolete

Structure of Lambda

event – event data passed to handler

context – runtime information to your handler. Type is LambdaContext

Handler can return a value, depends on invocation type

Stocks App

Implementation using standard Python

Lambda Function Python

import json

def handler(event, context):
    pass	

Convert to Lambda

API Gateway

Deploying


aws lambda update-function-code --function-name getStocks --zip-file fileb://lambda.zip

Lambda Versioning

  • Creates new version
  • $LATEST is current version
  • Previous versions immutable
  • Publish via AWS Console, CLI, or SDK

Testing

Testing Function

Lambda is just plain function call, so nosetests with asserts would work fine.

Using python-lambda-local

python-lambda-local is a library for running a lambda locally

https://pypi.org/project/python-lambda-local/


python-lambda-local -f handler -t 5 test.py event.json	

Localstack

https://github.com/localstack/localstack

Localstack Services

API Gateway, Kinesis, DynamoDB, DynamoDB Streams, Elasticsearch, S3, Firehose, Lambda, SNS, SQS, Redshift, ES (Elasticsearch Service), SES, Route53, CloudFormation, CloudWatch, SSM, SecretsManager

AWS SAM

Extension to CloudFormation, makes it easier to deploy without having to understand CF templates

Lambda Frameworks

Apex https://apex.run -- offers support for Clojure and Rust

Chalice https://github.com/aws/chalice

Serverless https://serverless.com/

край

Q & A

Andrew Lombardi / @kinabalu

Mystic Coders, LLC

bit.ly/websocketbook


https://github.com/kinabalu