Upgrade to Pro — share decks privately, control downloads, hide ads and more …

Going Serverless on AWS - Jannis Schaefer, Cosee

GoDays
January 30, 2019

Going Serverless on AWS - Jannis Schaefer, Cosee

Going Serverless on AWS. A journey through AWS’ serverless world - Jannis Schaefer, Cosee

GoDays

January 30, 2019
Tweet

More Decks by GoDays

Other Decks in Technology

Transcript

  1. serverless TL;DR Just me, my code and I no more

    http.Serve(), deployment,
 credit card bills, code changes, YAML,
 AWS knowledge, fun with handling state…
  2. serverless TL;DR ! Don’t need to manage servers Scales with

    usage / credit card Only costs when being used Availability and fault tolerance by design
  3. Heard of FaaS? • Function as a Service • Short

    running piece of customer owned code • Pay per use (RAM+CPU) * ms Used as glue between other Managed Services & www Hi, I am AWS Lambda!
  4. https://twitter.com/yogthos/status/1083226362993872897 λ in a nutshell Function triggers on Event Event

    can either be HTTP Request or from other AWS Services Lambda is executed in a sandbox
  5. Warm-up functions? Starting a new Lambda Runner creates a new

    Instance One Instance handles one request at a time Instances keep warm for about 5 - 10 Minutes with no traffic Startup ~200ms overhead
  6. Hello λ-World! package main import ( "fmt" "github.com/aws/aws-lambda-go/events" "github.com/aws/aws-lambda-go/lambda" )

    func main() { lambda.Start(Handler) } func Handler(ctx context.Context, request events.APIGatewayProxyRequest) (events.APIGatewayProxyResponse, error) { return events.APIGatewayProxyResponse{ Body: fmt.Sprintf("Hello, %v", request.QueryStringParameters["name"]), StatusCode: 200, }, nil }
  7. package main import ( "fmt" "github.com/aws/aws-lambda-go/events" "github.com/aws/aws-lambda-go/lambda" ) func main()

    { lambda.Start(Handler) } func Handler(ctx context.Context, request events.APIGatewayProxyRequest) (events.APIGatewayProxyResponse, error) { return events.APIGatewayProxyResponse{ Body: fmt.Sprintf("Hello, %v", request.QueryStringParameters["name"]), StatusCode: 200, }, nil }
  8. API Gateway • Entrypoint to Serverless Applications • Proxies HTTP

    Paths to Lambdas and other AWS Services • Terminates SSL • Helps handling auth • Provides documentation for APIs • Logging, Monitoring, Caching
  9. serverless Framework • Open Source Framework • Now officially backed

    by AWS • No CloudFormation • Supports other platforms as well • Takes care of nasty deployment things
  10. Introducing Pete • Pete likes to take photos • Wants

    to add filters to them so they look uber fancy • Wants to run it for cheap in the cloud Pete
  11. S3, a Cloud Native Dropbox • Amazon S3 - Simple

    Storage Service • Can save PBs of files in a single AWS Region • No direct File System Access • S3 FileTransfer Protocol also used by Google Cloud, Minio etc.
  12. Serverless Aurora • Part of AWS RDS • Behaves just

    like normal MySQL Server • Schedules workers on demand • Scale down to Zero • DB connections can keep open
  13. DynamoDB - NoSQL at scale • REST like Database Interface

    • Document Storage with Global Replication • Sometimes tricky indexing
 
 • Storage for product inforation at amazon.com
  14. Queues and notifications Simple Queue Service • Trigger Lambdas with

    1-10 Messages • Lambda ACKs successful processed msg
 Simple Notification Service • Message gets delivered to different subscribers • No monitoring of successful execution
  15. package main import ( ##... ) var db *sql.DB func

    main() { conn, _ #:= db.Conn(…) lambda.Start(Handler) } func Handler(ctx context.Context, request events.APIGatewayProxyRequest) (events.APIGatewayProxyResponse, error) { return ##... } Optimize Lambdas
  16. λ Layers • Provide Docker like Read-Only layers • Up

    to 250 MB of additional usable storage • Keeps deployment package small • Also used to provide new runtimes Your code Some libraries Cobol runtime?
  17. Try out serverless! • Download AWS SAM / Serverless Framework

    CLI • Most important Tools have free tier • Or just paste code inside AWS Lambda Console
  18. No AWS account? • Nearly every mayor Cloud Provider has

    FaaS solution • Most with free Trial Credits / free-tier • OpenFaaS runs anywhere* and anything • Many serverless platforms based on docker available * on Kubernetes & Docker Swarm including RaspberryPi
  19. Jannis Schaefer | cosee GmbH [email protected] | @jannisschaefer > blog.cosee.biz

    > jobs.cosee.biz > cosee.biz github.com/ashleymcnamara/gophers Me