amazon-web-servicesjarclojureaws-lambdaamazonica

How to create an AWS Lambda function from a Clojure project or a jar?


The Amazonica test for the AWS Lambda API (link) shows a simple example of creating a Lambda function from a Javascript blob (role is an ARN string for a role that can create Lambdas):

(def handler "exports.helloWorld = function(event, context) {
                  console.log('value1 = ' + event.key1)
                  console.log('value2 = ' + event.key2)
                  console.log('value3 = ' + event.key3)
                  context.done(null, 'Hello World')
                }")

(create-function :role role :function handler)

Does anyone know if create-function can create a Lambda from a jar? Would simply passing a file stream or a binary string of the jar to create-function be a bad idea, even if it did work?

I suppose I could just use a bash script with the AWS CLI to create a Lambda from a jar, but first I wanted to check if there is a known straightforward method of doing this in Clojure.

Another option would be to upload the jar to an S3 bucket and then let a CloudFormation script deploy it, based on the example here. It seems a little silly though, to have an S3 bucket just to hold build artefacts, when Lambda will be storing them itself.


Solution

  • You definitely can do the upload via S3, I have an example of doing so here: https://github.com/langford/clj-aws-lambda-example

    Very interested in this method as well. I agree the pit stop at S3 seems like it could be removed.