A New Clone Army:
ClojureScript on Lambda
Presented at @clojureireland on 7th Sept 2016.
Hit the [right-arrow]
key to proceed.
Presented at @clojureireland on 7th Sept 2016.
Hit the [right-arrow]
key to proceed.
"Serverless usually refers to an architectural pattern where the server-side logic is run in stateless compute containers that are event-driven and ephemeral."
- Software Engineering Daily podcast.
NodeJS
Java Virtual Machine
Python 2.7
AWS - Amazon Web Services
S3 - file storage service
API Gateway - give a Lambda function a public URL
EC2 - Amazon's virtual server.
Process photo / video (trigger: upload to S3 bucket)
Scheduled jobs for data-analytics, etc.
API backend for mobile or web app
Delay for cold starts of the container & JVM.
The frequency of cold starts is unpredictable.
OK for a 'background task' (startup time isn't critical).
Clojure rocks and JavaScript reaches.
Rich Hickey, NYC Clojure meet up 20 July 2011
(This is not required. We'll create the lambda on the command-line shortly.)
lein new cljs-lambda clonezero
(NB: no need to download cljs-lambda
in advance.)
project.clj
lein cljs-lambda default-iam-role
This is just enough to run the Lambda. It'll need more for database-access etc.
lein cljs-lambda deploy
lein cljs-lambda invoke work-magic '{ "magic-word": "clonezero-token", "spell": "adder", "x":29, "y":13 }'
Click on "Triggers" to use (say) API Gateway to trigger Lambda.
Note the public URL to call the Lambda.
Note the generated string of the API key.
http POST https://8hjoags647.execute-api.eu-west-1.amazonaws.com/prod/work-magic X-API-KEY:dy30nXp2gl3RSFGdCqjmH6h35o7SS8RL1vT7bwWr magic-word=clonezero-token spell=adder x:=13 y:=29
Note the API key. Httpie converts it to a HTTP header.
Httpie converts the other parameters to a JSON request-body.
DynamoDB - NoSQL datastore
S3 - filesystem
ElastiCache - Redis key-value store
SQS - queueing system (similar in principle to RabbitMQ)
RDS - Postgres, MySQL, MariaDB or Oracle.
Cheap-to-run
Massively scalable, with auto-scaling
Highly available
(Depending on Amazon's uptime is a better bet than servers you run.)
Amazon maintains the servers & other infrastructure.
For you: no upgrades, no need to apply security patches, etc.
Heavy dependence / lock-in to Amazon Web Services.
Delay for cold start (if you switch to Java).
Hard 300 second limit on a single Lambda.
(Workaround: spawn more Lambdas.)
No built-in support for dev. / staging / prod.
(Workaround: read config-file from S3, based on name of Lambda.)
Difficult to run arbitrary processes, as on a server.
(Workaround: run them on Amazon EC2 servers.)