garnaat / kappa

What precedes Lambda
http://kappa.readthedocs.org/en/develop/
Apache License 2.0
902 stars 89 forks source link

Support S3 code (avoid creating zip) #65

Open coopernurse opened 8 years ago

coopernurse commented 8 years ago

First off, thanks for creating this tool. I like the simplicity.

On my project I'm using Java, so I already have build tooling in place via mvn package. This produces a single JAR that contains several lambda functions.

Consequently I'd like to be able to do something like this:

#!/bin/bash
set -e

# build JAR and upload to S3
mvn clean package
aws s3 cp target/myproj-with-deps.jar s3://mybucket/myproj.jar

# use kappa to register lambdas
kappa --config lambda/func1.yml deploy
kappa --config lambda/func2.yml deploy

I have a quick and dirty version of the above working on my fork. I augmented the lambda section of the config to support an option code block. If this block is present, the S3 keys are set in the create_function and update_function_code calls. For example:


---
name: hello
lambda:
  # new optional section - if present, no ZIP is created and S3 code is used
  code:
    bucket: mybucket
    key: myproj.jar    
  description: Hello Cats
  handler: com.bitmechanic.foo.LambdaHello::handleRequest
  runtime: java8
  memory_size: 128
  timeout: 10

One consequence of my current implementation is that the config file is not generated in the S3 case, as this is done as part of the ZIP bundling. This is what I'd expect, as I'm not relying on kappa to bundle my code for me, so I wouldn't expect configuration manifests to be injected into my JAR.

Would you entertain a PR with this work?

I'm open to feedback on the YAML changes. I also implemented this by factoring out all the ZIP stuff into a separate class in function.py such there are S3Code and ZipCode classes. Function.update and Function.create delegate to these classes.

Before I submit a PR I need to clean things up, write docs, etc. But before I got too far I wanted to open up the conversation here and get preliminary feedback on the enhancement.

Thanks!

josegonzalez commented 8 years ago

@coopernurse Sounds like a great idea! I'd be happy to take a look at such a pr :) Your initial implementation looks good, lets see how it works in code and I can give further feedback then :)

coopernurse commented 8 years ago

Excellent - here's the related PR

https://github.com/garnaat/kappa/pull/68