https://pulumi.com logo
Title
t

tall-librarian-49374

07/11/2018, 3:15 PM
How do I package a java lambda? The following fails with `panic: runtime error: invalid memory address or nil pointer dereference`:
let javaLambda = new aws.lambda.Function("aws-java", {
    code: new pulumi.asset.FileArchive("./java/target/lambda-java-example-1.0-SNAPSHOT.jar"),
b

big-piano-35669

07/11/2018, 3:35 PM
Ah, very interesting. I think we assume archives are zips/tars, and not jars, and fail to read it. I suspect using a zip file would work (https://docs.aws.amazon.com/lambda/latest/dg/create-deployment-pkg-zip-java.html), however obviously we want to ensure jar files will work.
If it were a
new pulumi.asset.FileAsset("/path/to/my.jar")
, we wouldn't try to open it, and it might work. However, I'll defer to @white-balloon-205, @bitter-oil-46081, and @microscopic-florist-22719 who know this territory better than me -- namely, it might be that lambdas require archives, I honestly can't remember at the moment.
m

microscopic-florist-22719

07/11/2018, 5:10 PM
I think what you want is an `AssetArchive`:
let javaLambda = new aws.lambda.Function("aws-java", {
    code: new pulumi.asset.AssetArchive({
"lambda-java-example-1.0-SNAPSHOT.jar": new pulumi.asset.AssetFile("./java/target/lambda-java-example-1.0-SNAPSHOT.jar"),
}),
t

tall-librarian-49374

07/11/2018, 7:00 PM
@big-piano-35669
FileAsset(path)
says
expected an asset, but filename is not an asset
...
@microscopic-florist-22719 Wouldn't this wrap jar into another zip layer?
m

microscopic-florist-22719

07/11/2018, 7:08 PM
It will, yes.
w

white-balloon-205

07/11/2018, 7:09 PM
Yes - I believe this is just a bug. The code as @tall-librarian-49374 originally wrote it should work. Once https://github.com/pulumi/pulumi/issues/280 is addressed, we should be able to support using a plain FileAsset here instead of having any knowledge this is an archive in the first place (which we shouldn't need to know about in this case).
t

tall-librarian-49374

07/11/2018, 7:10 PM
@microscopic-florist-22719 Jar inside zip won't work - I tried and AWS doesn't expect that
OK, found a workaround for now:
code: new pulumi.asset.AssetArchive({
        "lib/lambda-java-example-1.0-SNAPSHOT.jar": new pulumi.asset.FileAsset("./java/target/lambda-java-example-1.0-SNAPSHOT.jar"),
    }),
By the way, the crash seems to leave node.js in some eternal loop, so CPU gets 100% after several runs and laptop is really hot now...
m

microscopic-florist-22719

07/11/2018, 7:49 PM
cc @incalculable-sundown-82514
i

incalculable-sundown-82514

07/11/2018, 7:50 PM
yeah, sorry - that’s a known issue that is definitely on our radar for fixing.
b

big-piano-35669

07/11/2018, 8:10 PM
In the meantime, I think you can use this approach to create a zip file and it will work? Not ideal but should unblock things. @white-balloon-205 @microscopic-florist-22719 Is that right? https://docs.aws.amazon.com/lambda/latest/dg/create-deployment-pkg-zip-java.html
w

white-balloon-205

07/11/2018, 8:12 PM
I believe @tall-librarian-49374 is unblocked with the code he shared a couple messages up thread. Frankly, I'm not entirely clear why that works, but I'm glad there is a workaround. As part of https://github.com/pulumi/pulumi/issues/280 we need to simplify the overall distinctions between Assets and Archives to make this space simpler and less error prone.
t

tall-librarian-49374

07/11/2018, 8:48 PM
Yes, I'm unblocked. AWS accepts a zip with jars in lib folder.
Thanks for your help. I believe you have all the issues in place.
b

big-piano-35669

07/11/2018, 8:54 PM
Great, glad that did the trick! Sorry for the hassles.
t

tall-librarian-49374

07/11/2018, 9:14 PM
Np, it works great overall! Now I have templates for Lambdas in all supported languages. Time for a blog post and then looking at Azure.
🎉 3
3
b

big-piano-35669

07/11/2018, 9:14 PM
Awesome! I can't wait to read it!