2

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.

birnbaum
  • 4,718
  • 28
  • 37
Dan Ross
  • 3,596
  • 4
  • 31
  • 60

2 Answers2

1

I'm sorry that I can't thoroughly answer your question, but I've tried to deploy a hello-world clojure app, so to hopefully point you in the right direction:

  • Login to your AWS Console
  • Navigate to Lambda
  • Open up the Hello World sample app
  • From a dropdown menu select Java 8
  • Upload your JAR directly
  • Fill in the Classpath to your starter function (don't ask me why; I haven't gotten this right yet either)
  • Click the Roles box and follow the prompts to create the default reccomended roles config

If this isn't helpful please let me know!

Adam Lee
  • 1,784
  • 1
  • 11
  • 15
  • The direct jar upload method eventually fails as your jar gets bigger and bigger. I don't remember the exact threshold, but it will be suddenly a bit of work as you figure out S3. – Michael Dec 22 '16 at 06:37
1

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.

Michael
  • 419
  • 3
  • 11
  • 2
    In case anything happens to that example, the relevant tool is `lein lambda` from https://github.com/mhjort/clj-lambda-utils. Looks like a good solution to me, I will try it next time I'm working with Lambdas. – Dan Ross Dec 21 '16 at 21:30