Top Banner
Serverless Adventures with AWS Lambda and Clojure
51

Serverless adventures with AWS Lambda and Clojure

Jan 14, 2017

Download

Software

Lars Trieloff
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: Serverless adventures with AWS Lambda and Clojure

Serverless Adventures with AWS Lambda and

Clojure

Page 2: 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: Serverless adventures with AWS Lambda and Clojure

Lars Trieloff!❤! @trieloff!" @trieloff

Page 4: Serverless adventures with AWS Lambda and Clojure

!"!"#$%&'

Page 5: Serverless adventures with AWS Lambda and Clojure

!

Page 6: Serverless adventures with AWS Lambda and Clojure

What?

Page 7: Serverless adventures with AWS Lambda and Clojure

Excel + HTTP = Excelsior

Page 8: Serverless adventures with AWS Lambda and Clojure

!"github.com/trieloff/excelsior

Page 9: Serverless adventures with AWS Lambda and Clojure

!

Page 10: Serverless adventures with AWS Lambda and Clojure

Why?

Page 11: Serverless adventures with AWS Lambda and Clojure

! Clojure

Page 12: Serverless adventures with AWS Lambda and Clojure

λ !

Page 13: Serverless adventures with AWS Lambda and Clojure

! 12 ✕12factor.net

Page 14: Serverless adventures with AWS Lambda and Clojure

! Swaggerswagger.io

Page 15: Serverless adventures with AWS Lambda and Clojure

!"?

Page 16: Serverless adventures with AWS Lambda and Clojure

AWS Lambda!

Page 17: Serverless adventures with AWS Lambda and Clojure

!" = #

Page 18: Serverless adventures with AWS Lambda and Clojure

!" = #

Page 19: Serverless adventures with AWS Lambda and Clojure

!"

Page 20: Serverless adventures with AWS Lambda and Clojure

AWS λ + Clojure λ = ♥

Page 21: Serverless adventures with AWS Lambda and Clojure

!

Page 22: Serverless adventures with AWS Lambda and Clojure

Sounds good.

Page 23: Serverless adventures with AWS Lambda and Clojure

Sounds too good.

Page 24: Serverless adventures with AWS Lambda and Clojure

Sounds too good to be true.

Page 25: Serverless adventures with AWS Lambda and Clojure

If something sounds too good to be true, it

probably is.

Page 26: Serverless adventures with AWS Lambda and Clojure

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

Page 27: Serverless adventures with AWS Lambda and Clojure

!

Page 28: Serverless adventures with AWS Lambda and Clojure

How?

Page 29: 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: 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: Serverless adventures with AWS Lambda and Clojure

!

Page 32: Serverless adventures with AWS Lambda and Clojure

Problems?

Page 33: Serverless adventures with AWS Lambda and Clojure

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

Page 34: Serverless adventures with AWS Lambda and Clojure

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

Page 35: Serverless adventures with AWS Lambda and Clojure

!"AWS API Gateway

Page 36: Serverless adventures with AWS Lambda and Clojure

!"AWS IAM Permissions

Page 37: 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: Serverless adventures with AWS Lambda and Clojure

!

Page 39: Serverless adventures with AWS Lambda and Clojure

Tips?

Page 40: Serverless adventures with AWS Lambda and Clojure

Think small100 LOC should be

enough for a Lambda function. !

Page 41: Serverless adventures with AWS Lambda and Clojure

Think modular

Two tiny functions are better than one large

function. !

Page 42: Serverless adventures with AWS Lambda and Clojure

!"github.com/trieloff/salvador

Page 43: Serverless adventures with AWS Lambda and Clojure

Think Stateless

simplicity, performance, composablity ☠

Page 44: 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: Serverless adventures with AWS Lambda and Clojure

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

Page 46: Serverless adventures with AWS Lambda and Clojure

Smile & ShareCommunity eats code for

breakfast. ☕

Page 47: Serverless adventures with AWS Lambda and Clojure

!

Page 48: Serverless adventures with AWS Lambda and Clojure

Page 49: Serverless adventures with AWS Lambda and Clojure

AWS λ + Clojure λ = ♥

Page 50: Serverless adventures with AWS Lambda and Clojure

! Rainbow Parentheses make " #