Top Banner
Serverless Adventures with AWS Lambda and Clojure
51

Lars Trierloff - Serverless Adventures with AWS Lambda and Clojure

Apr 16, 2017

Download

Internet

ServerlessConf
Welcome message from author
This document is posted to help you gain knowledge. Please leave a comment to let me know what you think about it! Share it to your friends and learn new things together.
Transcript
Page 1: Lars Trierloff - Serverless Adventures with AWS Lambda and Clojure

Serverless Adventures with AWS Lambda and

Clojure

Page 2: Lars Trierloff - Serverless Adventures with AWS Lambda and Clojure

________ ______ __ ___/______________ ________________ /___________________ _____ \_ _ \_ ___/_ | / / _ \_ ___/_ /_ _ \_ ___/_ ___/ ____/ // __/ / __ |/ // __/ / _ / / __/(__ )_(__ ) /____/ \___//_/ _____/ \___//_/ /_/ \___//____/ /____/

.d8b. d8888b. db db d88888b d8b db d888888b db db d8888b. d88888b .d8888. db d8b db d888888b d888888b db db d8' `8b 88 `8D 88 88 88' 888o 88 `~~88~~' 88 88 88 `8D 88' 88' YP 88 I8I 88 `88' `~~88~~' 88 88 88ooo88 88 88 Y8 8P 88ooooo 88V8o 88 88 88 88 88oobY' 88ooooo `8bo. 88 I8I 88 88 88 88ooo88 88~~~88 88 88 `8b d8' 88~~~~~ 88 V8o88 88 88 88 88`8b 88~~~~~ `Y8b. Y8 I8I 88 88 88 88~~~88 88 88 88 .8D `8bd8' 88. 88 V888 88 88b d88 88 `88. 88. db 8D `8b d8'8b d8' .88. 88 88 88 YP YP Y8888D' YP Y88888P VP V8P YP ~Y8888P' 88 YD Y88888P `8888Y' `8b8' `8d8' Y888888P YP YP YP

┌───────────────────────────────────────────────────────────────────────────────────────────────────────────────────────┐ │ │ │ │ │ ___ ____ __ ____ _______. __ ___ .___ ___. .______ _______ ___ │ │ / \ \ \ / \ / / / | | | / \ | \/ | | _ \ | \ / \ │ │ / ^ \ \ \/ \/ / | (----` | | / ^ \ | \ / | | |_) | | .--. | / ^ \ │ │ / /_\ \ \ / \ \ | | / /_\ \ | |\/| | | _ < | | | | / /_\ \ │ │ / _____ \ \ /\ / .----) | | `----./ _____ \ | | | | | |_) | | '--' | / _____ \ │ │ /__/ \__\ &&&&&&&&&&/ |_______/ |_______/__/ \__\ |__| |__| |______/ |_______/ /__/ \__\ │ │ &::::::::::& │ │ &::::&&&:::::& ╔════════════════════════════════════════════════════════════════════════════════╗ │ └────────────────&::::&───&::::&────╣ ╠──┘ &::::& &::::& ║ ║ &::::&&&::::& ║ ______ __ ______ __ __ __ .______ _______ ║ &::::::::::& ║ / || | / __ \ | | | | | | | _ \ | ____| ║ &:::::::&& ║ | ,----'| | | | | | | | | | | | | |_) | | |__ ║ &::::::::& &&&& ║ | | | | | | | | .--. | | | | | | | / | __| ║ &:::::&&::& &:::& ║ | `----.| `----.| `--' | | `--' | | `--' | | |\ \----.| |____ ║ &:::::& &::&&:::&& ║ \______||_______| \______/ \______/ \______/ | _| `._____||_______| ║ &:::::& &:::::& ║ ║ &:::::& &::::& ║ ║ &::::::&&&&::::::&& ╚════════════════════════════════════════════════════════════════════════════════╝ &&::::::::&&&::::& &&&&&&&& &&&&&

Page 3: Lars Trierloff - Serverless Adventures with AWS Lambda and Clojure

Lars Trieloff!❤! @trieloff!" @trieloff

Page 4: Lars Trierloff - Serverless Adventures with AWS Lambda and Clojure

!"!"#$%&'

Page 5: Lars Trierloff - Serverless Adventures with AWS Lambda and Clojure

!

Page 6: Lars Trierloff - Serverless Adventures with AWS Lambda and Clojure

What?

Page 7: Lars Trierloff - Serverless Adventures with AWS Lambda and Clojure

Excel + HTTP = Excelsior

Page 8: Lars Trierloff - Serverless Adventures with AWS Lambda and Clojure

!"github.com/trieloff/excelsior

Page 9: Lars Trierloff - Serverless Adventures with AWS Lambda and Clojure

!

Page 10: Lars Trierloff - Serverless Adventures with AWS Lambda and Clojure

Why?

Page 11: Lars Trierloff - Serverless Adventures with AWS Lambda and Clojure

! Clojure

Page 12: Lars Trierloff - Serverless Adventures with AWS Lambda and Clojure

λ !

Page 13: Lars Trierloff - Serverless Adventures with AWS Lambda and Clojure

! 12 ✕12factor.net

Page 14: Lars Trierloff - Serverless Adventures with AWS Lambda and Clojure

! Swaggerswagger.io

Page 15: Lars Trierloff - Serverless Adventures with AWS Lambda and Clojure

!"?

Page 16: Lars Trierloff - Serverless Adventures with AWS Lambda and Clojure

AWS Lambda!

Page 17: Lars Trierloff - Serverless Adventures with AWS Lambda and Clojure

!" = #

Page 18: Lars Trierloff - Serverless Adventures with AWS Lambda and Clojure

!" = #

Page 19: Lars Trierloff - Serverless Adventures with AWS Lambda and Clojure

!"

Page 20: Lars Trierloff - Serverless Adventures with AWS Lambda and Clojure

AWS λ + Clojure λ = ♥

Page 21: Lars Trierloff - Serverless Adventures with AWS Lambda and Clojure

!

Page 22: Lars Trierloff - Serverless Adventures with AWS Lambda and Clojure

Sounds good.

Page 23: Lars Trierloff - Serverless Adventures with AWS Lambda and Clojure

Sounds too good.

Page 24: Lars Trierloff - Serverless Adventures with AWS Lambda and Clojure

Sounds too good to be true.

Page 25: Lars Trierloff - Serverless Adventures with AWS Lambda and Clojure

If something sounds too good to be true, it

probably is.

Page 26: Lars Trierloff - Serverless Adventures with AWS Lambda and Clojure

┌─────────────┐ │ │ │ │ │ Clojure │ │ ┌─────┼───────┐ │ │ ! │ │ └───────┼─────┘ │ │ AWS Lambda │ │ │ │ │ └─────────────┘

Page 27: Lars Trierloff - Serverless Adventures with AWS Lambda and Clojure

!

Page 28: Lars Trierloff - Serverless Adventures with AWS Lambda and Clojure

How?

Page 29: Lars Trierloff - Serverless Adventures with AWS Lambda and Clojure

→ ! github.com/metosin/compojure-api→ " github.com/jpb/ring-aws-lambda-adapter

→ # github.com/mjul/docjure→ ⭕ circleci.com

→ % github.com/mhjort/lein-clj-lambda

Page 30: Lars Trierloff - Serverless Adventures with AWS Lambda and Clojure

┌────────────────────────┐ ┌────────────────────────┐ │ ┌────────────────────┐ │ │ │ │ │ ┌────────────────┐ │ │ │ │ │ │ │ ┌────────────┐ │ │ │ │ │ │ │ │ │ Docjure !│ │ │ │ │ │ │ │ │ └────────────┘ │ │ │ ┌────────────┐ │ AWS API Gateway │ │ │ │ My code " │ │ │ ┌────────▶│swagger.json│─────Import─────▶│ │ │ │ └────────────────┘ │ │ Export └────────────┘ │ │ │ │ Compojure API # ├─┼─────┘ │ │ │ └────────────────────┘ │ │ │ │ Ring Lambda Adapter $ │ │ │ └────────────────────────┘ └────────────────────────┘ │ │ │ Proxy │ │ │ ▼ │ ┌────────────────────────┐ │ │ │ │ │ │ │ │ │ │ │ │ │ ┌────────────┐ │ AWS Lambda │ └───────────Build % ─────▶│ server.jar │────Deploy──────▶│ │ └────────────┘ │ │ │ │ │ │ │ │ └────────────────────────┘

Page 31: Lars Trierloff - Serverless Adventures with AWS Lambda and Clojure

!

Page 32: Lars Trierloff - Serverless Adventures with AWS Lambda and Clojure

Problems?

Page 33: Lars Trierloff - Serverless Adventures with AWS Lambda and Clojure

┌─────────────┐ │ │ │ │ │ Clojure │ │ ┌─────┼───────┐ │ │!"#│ │ └───────┼─────┘ │ │ AWS Lambda │ │ │ │ │ └─────────────┘

Page 34: Lars Trierloff - Serverless Adventures with AWS Lambda and Clojure

!"github.com/trieloff/lein-aws-apigateway

Page 35: Lars Trierloff - Serverless Adventures with AWS Lambda and Clojure

!"AWS API Gateway

Page 36: Lars Trierloff - Serverless Adventures with AWS Lambda and Clojure

!"AWS IAM Permissions

Page 37: Lars Trierloff - Serverless Adventures with AWS Lambda and Clojure

Execution failed due to configuration error: Invalid permissions on Lambda function

aws lambda add-permission \ --function-name <name> \ --statement-id <someid> \ --action "lambda:*" \ --principal "apigateway.amazonaws.com"

! docs.aws.amazon.com/cli/latest/reference/lambda/add-permission.html

Page 38: Lars Trierloff - Serverless Adventures with AWS Lambda and Clojure

!

Page 39: Lars Trierloff - Serverless Adventures with AWS Lambda and Clojure

Tips?

Page 40: Lars Trierloff - Serverless Adventures with AWS Lambda and Clojure

Think small100 LOC should be

enough for a Lambda function. !

Page 41: Lars Trierloff - Serverless Adventures with AWS Lambda and Clojure

Think modular

Two tiny functions are better than one large

function. !

Page 42: Lars Trierloff - Serverless Adventures with AWS Lambda and Clojure

!"github.com/trieloff/salvador

Page 43: Lars Trierloff - Serverless Adventures with AWS Lambda and Clojure

Think Stateless

simplicity, performance, composablity ☠

Page 44: Lars Trierloff - Serverless Adventures with AWS Lambda and Clojure

Be lazySit, don’t stand on the

shoulders of giants. Re-use, don’t re-invent. ♻

Page 45: Lars Trierloff - Serverless Adventures with AWS Lambda and Clojure

┌──────────────────┐ ┌──────────────────┐ ┌──────────────────┐ │ │ │ │ │ │ │ Typeform │───Redirect──▶│ Excelsior │───Redirect──▶│ Salvador │ │ │ │ │ │ │ └──────────────────┘ └──────────────────┘ └──────────────────┘ ▲ ▲ │ │ Spreadsheet Template │ │ │ │ ┌──────────────────┐ ┌──────────────────┐ │ │ │ │ │ S3 │ │ S3 │ │ │ │ │ └──────────────────┘ └──────────────────┘

Page 46: Lars Trierloff - Serverless Adventures with AWS Lambda and Clojure

Smile & ShareCommunity eats code for

breakfast. ☕

Page 47: Lars Trierloff - Serverless Adventures with AWS Lambda and Clojure

!

Page 48: Lars Trierloff - Serverless Adventures with AWS Lambda and Clojure

Page 49: Lars Trierloff - Serverless Adventures with AWS Lambda and Clojure

AWS λ + Clojure λ = ♥

Page 50: Lars Trierloff - Serverless Adventures with AWS Lambda and Clojure

! Rainbow Parentheses make " #