lars trierloff - serverless adventures with aws lambda and clojure

51
Serverless Adventures with AWS Lambda and Clojure

Upload: serverlessconf

Post on 16-Apr-2017

1.016 views

Category:

Internet


1 download

TRANSCRIPT

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

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

Lars Trieloff!❤! @trieloff!" @trieloff

!"!"#$%&'

!

What?

Excel + HTTP = Excelsior

!"github.com/trieloff/excelsior

!

Why?

! Clojure

λ !

! 12 ✕12factor.net

! Swaggerswagger.io

!"?

AWS Lambda!

!" = #

!" = #

!"

AWS λ + Clojure λ = ♥

!

Sounds good.

Sounds too good.

Sounds too good to be true.

If something sounds too good to be true, it

probably is.

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

!

How?

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

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

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

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

!

Problems?

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

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

!"AWS API Gateway

!"AWS IAM Permissions

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

!

Tips?

Think small100 LOC should be

enough for a Lambda function. !

Think modular

Two tiny functions are better than one large

function. !

!"github.com/trieloff/salvador

Think Stateless

simplicity, performance, composablity ☠

Be lazySit, don’t stand on the

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

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

Smile & ShareCommunity eats code for

breakfast. ☕

!

AWS λ + Clojure λ = ♥

! Rainbow Parentheses make " #