简体   繁体   中英

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.

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!

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM