How do I package a java lambda? The following fail...
# general
t
How do I package a java lambda? The following fails with `panic: runtime error: invalid memory address or nil pointer dereference`:
Copy code
let javaLambda = new aws.lambda.Function("aws-java", {
    code: new pulumi.asset.FileArchive("./java/target/lambda-java-example-1.0-SNAPSHOT.jar"),
b
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
I think what you want is an `AssetArchive`:
Copy code
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
@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
It will, yes.
w
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
@microscopic-florist-22719 Jar inside zip won't work - I tried and AWS doesn't expect that
OK, found a workaround for now:
Copy code
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
cc @incalculable-sundown-82514
i
yeah, sorry - that’s a known issue that is definitely on our radar for fixing.
b
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
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
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
Great, glad that did the trick! Sorry for the hassles.
t
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
Awesome! I can't wait to read it!