SlideShare a Scribd company logo
1 of 51
Download to read offline
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
! Swagger
swagger.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 small
100 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 lazy
Sit, don’t stand on the
shoulders of giants. Re-
use, don’t re-invent. ♻
┌──────────────────┐ ┌──────────────────┐ ┌──────────────────┐
│ │ │ │ │ │
│ Typeform │───Redirect──▶│ Excelsior │───Redirect──▶│ Salvador │
│ │ │ │ │ │
└──────────────────┘ └──────────────────┘ └──────────────────┘
▲ ▲
│ │
Spreadsheet Template
│ │
│ │
┌──────────────────┐ ┌──────────────────┐
│ │ │ │
│ S3 │ │ S3 │
│ │ │ │
└──────────────────┘ └──────────────────┘
Smile & Share
Community eats code for
breakfast. ☕
!
⏰
AWS λ + Clojure λ = ♥
! Rainbow Parentheses make " #
))))))))))))*

More Related Content

More from ServerlessConf

Paul Johnston - What I Wish I'd Known Last Year
Paul Johnston - What I Wish I'd Known Last YearPaul Johnston - What I Wish I'd Known Last Year
Paul Johnston - What I Wish I'd Known Last YearServerlessConf
 
Tomasz Janczuk - Webtaskalifragilistexpialidocious
Tomasz Janczuk - WebtaskalifragilistexpialidociousTomasz Janczuk - Webtaskalifragilistexpialidocious
Tomasz Janczuk - WebtaskalifragilistexpialidociousServerlessConf
 
Charity Hound - Serverless, NoOps, The Tooth Fairy
Charity Hound - Serverless, NoOps, The Tooth FairyCharity Hound - Serverless, NoOps, The Tooth Fairy
Charity Hound - Serverless, NoOps, The Tooth FairyServerlessConf
 
Sam Kroonenburg and Pete Sbarski - The Story of a Serverless Startup
Sam Kroonenburg and Pete Sbarski - The Story of a Serverless StartupSam Kroonenburg and Pete Sbarski - The Story of a Serverless Startup
Sam Kroonenburg and Pete Sbarski - The Story of a Serverless StartupServerlessConf
 
Patrick Debois - From Serverless to Servicefull
Patrick Debois - From Serverless to ServicefullPatrick Debois - From Serverless to Servicefull
Patrick Debois - From Serverless to ServicefullServerlessConf
 
Kapil Thangavelu - Cloud Custodian
Kapil Thangavelu - Cloud CustodianKapil Thangavelu - Cloud Custodian
Kapil Thangavelu - Cloud CustodianServerlessConf
 
Joe Emison - 10X Product Development
Joe Emison - 10X Product DevelopmentJoe Emison - 10X Product Development
Joe Emison - 10X Product DevelopmentServerlessConf
 
Frederic Lavigne and Stephen Fink - Serverless Video Processing with IBM Blue...
Frederic Lavigne and Stephen Fink - Serverless Video Processing with IBM Blue...Frederic Lavigne and Stephen Fink - Serverless Video Processing with IBM Blue...
Frederic Lavigne and Stephen Fink - Serverless Video Processing with IBM Blue...ServerlessConf
 
Eric Windisch - Building Composable Serverless Apps
Eric Windisch - Building Composable Serverless AppsEric Windisch - Building Composable Serverless Apps
Eric Windisch - Building Composable Serverless AppsServerlessConf
 
Donald Ferguson - Old Programmers Can Learn New Tricks
Donald Ferguson - Old Programmers Can Learn New TricksDonald Ferguson - Old Programmers Can Learn New Tricks
Donald Ferguson - Old Programmers Can Learn New TricksServerlessConf
 
Ben Kehoe - Serverless Architecture for the Internet of Things
Ben Kehoe - Serverless Architecture for the Internet of ThingsBen Kehoe - Serverless Architecture for the Internet of Things
Ben Kehoe - Serverless Architecture for the Internet of ThingsServerlessConf
 

More from ServerlessConf (11)

Paul Johnston - What I Wish I'd Known Last Year
Paul Johnston - What I Wish I'd Known Last YearPaul Johnston - What I Wish I'd Known Last Year
Paul Johnston - What I Wish I'd Known Last Year
 
Tomasz Janczuk - Webtaskalifragilistexpialidocious
Tomasz Janczuk - WebtaskalifragilistexpialidociousTomasz Janczuk - Webtaskalifragilistexpialidocious
Tomasz Janczuk - Webtaskalifragilistexpialidocious
 
Charity Hound - Serverless, NoOps, The Tooth Fairy
Charity Hound - Serverless, NoOps, The Tooth FairyCharity Hound - Serverless, NoOps, The Tooth Fairy
Charity Hound - Serverless, NoOps, The Tooth Fairy
 
Sam Kroonenburg and Pete Sbarski - The Story of a Serverless Startup
Sam Kroonenburg and Pete Sbarski - The Story of a Serverless StartupSam Kroonenburg and Pete Sbarski - The Story of a Serverless Startup
Sam Kroonenburg and Pete Sbarski - The Story of a Serverless Startup
 
Patrick Debois - From Serverless to Servicefull
Patrick Debois - From Serverless to ServicefullPatrick Debois - From Serverless to Servicefull
Patrick Debois - From Serverless to Servicefull
 
Kapil Thangavelu - Cloud Custodian
Kapil Thangavelu - Cloud CustodianKapil Thangavelu - Cloud Custodian
Kapil Thangavelu - Cloud Custodian
 
Joe Emison - 10X Product Development
Joe Emison - 10X Product DevelopmentJoe Emison - 10X Product Development
Joe Emison - 10X Product Development
 
Frederic Lavigne and Stephen Fink - Serverless Video Processing with IBM Blue...
Frederic Lavigne and Stephen Fink - Serverless Video Processing with IBM Blue...Frederic Lavigne and Stephen Fink - Serverless Video Processing with IBM Blue...
Frederic Lavigne and Stephen Fink - Serverless Video Processing with IBM Blue...
 
Eric Windisch - Building Composable Serverless Apps
Eric Windisch - Building Composable Serverless AppsEric Windisch - Building Composable Serverless Apps
Eric Windisch - Building Composable Serverless Apps
 
Donald Ferguson - Old Programmers Can Learn New Tricks
Donald Ferguson - Old Programmers Can Learn New TricksDonald Ferguson - Old Programmers Can Learn New Tricks
Donald Ferguson - Old Programmers Can Learn New Tricks
 
Ben Kehoe - Serverless Architecture for the Internet of Things
Ben Kehoe - Serverless Architecture for the Internet of ThingsBen Kehoe - Serverless Architecture for the Internet of Things
Ben Kehoe - Serverless Architecture for the Internet of Things
 

Lars Trierloff - Serverless Adventures with AWS Lambda and Clojure

  • 1. Serverless Adventures with AWS Lambda and Clojure
  • 2. ________ ______ __ ___/______________ ________________ /___________________ _____ _ _ _ ___/_ | / / _ _ ___/_ /_ _ _ ___/_ ___/ ____/ // __/ / __ |/ // __/ / _ / / __/(__ )_(__ ) /____/ ___//_/ _____/ ___//_/ /_/ ___//____/ /____/ .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 ┌───────────────────────────────────────────────────────────────────────────────────────────────────────────────────────┐ │ │ │ │ │ ___ ____ __ ____ _______. __ ___ .___ ___. .______ _______ ___ │ │ / / / / / | | | / | / | | _ | / │ │ / ^ / / / | (----` | | / ^ | / | | |_) | | .--. | / ^ │ │ / /_ / | | / /_ | |/| | | _ < | | | | / /_ │ │ / _____ / / .----) | | `----./ _____ | | | | | |_) | | '--' | / _____ │ │ /__/ __ &&&&&&&&&&/ |_______/ |_______/__/ __ |__| |__| |______/ |_______/ /__/ __ │ │ &::::::::::& │ │ &::::&&&:::::& ╔════════════════════════════════════════════════════════════════════════════════╗ │ └────────────────&::::&───&::::&────╣ ╠──┘ &::::& &::::& ║ ║ &::::&&&::::& ║ ______ __ ______ __ __ __ .______ _______ ║ &::::::::::& ║ / || | / __ | | | | | | | _ | ____| ║ &:::::::&& ║ | ,----'| | | | | | | | | | | | | |_) | | |__ ║ &::::::::& &&&& ║ | | | | | | | | .--. | | | | | | | / | __| ║ &:::::&&::& &:::& ║ | `----.| `----.| `--' | | `--' | | `--' | | | ----.| |____ ║ &:::::& &::&&:::&& ║ ______||_______| ______/ ______/ ______/ | _| `._____||_______| ║ &:::::& &:::::& ║ ║ &:::::& &::::& ║ ║ &::::::&&&&::::::&& ╚════════════════════════════════════════════════════════════════════════════════╝ &&::::::::&&&::::& &&&&&&&& &&&&&
  • 5. !
  • 7. Excel + HTTP = Excelsior
  • 9. !
  • 10. Why?
  • 12. λ !
  • 15. !"?
  • 19. !"
  • 20. AWS λ + Clojure λ = ♥
  • 21. !
  • 24. Sounds too good to be true.
  • 25. If something sounds too good to be true, it probably is.
  • 26. ┌─────────────┐ │ │ │ │ │ Clojure │ │ ┌─────┼───────┐ │ │ ! │ │ └───────┼─────┘ │ │ AWS Lambda │ │ │ │ │ └─────────────┘
  • 27. !
  • 28. How?
  • 29. → ! github.com/metosin/compojure-api → " github.com/jpb/ring-aws-lambda-adapter → # github.com/mjul/docjure → ⭕ circleci.com → % github.com/mhjort/lein-clj-lambda
  • 30. ┌────────────────────────┐ ┌────────────────────────┐ │ ┌────────────────────┐ │ │ │ │ │ ┌────────────────┐ │ │ │ │ │ │ │ ┌────────────┐ │ │ │ │ │ │ │ │ │ Docjure !│ │ │ │ │ │ │ │ │ └────────────┘ │ │ │ ┌────────────┐ │ AWS API Gateway │ │ │ │ My code " │ │ │ ┌────────▶│swagger.json│─────Import─────▶│ │ │ │ └────────────────┘ │ │ Export └────────────┘ │ │ │ │ Compojure API # ├─┼─────┘ │ │ │ └────────────────────┘ │ │ │ │ Ring Lambda Adapter $ │ │ │ └────────────────────────┘ └────────────────────────┘ │ │ │ Proxy │ │ │ ▼ │ ┌────────────────────────┐ │ │ │ │ │ │ │ │ │ │ │ │ │ ┌────────────┐ │ AWS Lambda │ └───────────Build % ─────▶│ server.jar │────Deploy──────▶│ │ └────────────┘ │ │ │ │ │ │ │ │ └────────────────────────┘
  • 31. !
  • 33. ┌─────────────┐ │ │ │ │ │ Clojure │ │ ┌─────┼───────┐ │ │!"#│ │ └───────┼─────┘ │ │ AWS Lambda │ │ │ │ │ └─────────────┘
  • 37. 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
  • 38. !
  • 39. Tips?
  • 40. Think small 100 LOC should be enough for a Lambda function. !
  • 41. Think modular Two tiny functions are better than one large function. !
  • 44. Be lazy Sit, don’t stand on the shoulders of giants. Re- use, don’t re-invent. ♻
  • 45. ┌──────────────────┐ ┌──────────────────┐ ┌──────────────────┐ │ │ │ │ │ │ │ Typeform │───Redirect──▶│ Excelsior │───Redirect──▶│ Salvador │ │ │ │ │ │ │ └──────────────────┘ └──────────────────┘ └──────────────────┘ ▲ ▲ │ │ Spreadsheet Template │ │ │ │ ┌──────────────────┐ ┌──────────────────┐ │ │ │ │ │ S3 │ │ S3 │ │ │ │ │ └──────────────────┘ └──────────────────┘
  • 46. Smile & Share Community eats code for breakfast. ☕
  • 47. !
  • 48.
  • 49. AWS λ + Clojure λ = ♥