Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

zio-lambda-example cannot find main class zio.lambda.example.SimpleHandler$ #213

Closed
Isaacwhyuenac opened this issue Jul 1, 2023 · 14 comments

Comments

@Isaacwhyuenac
Copy link

Hi I managed to upload zio-lambda as layer but I cannot manage to get the zio-lambda-example running. I am using the current master branch of the repo to do the testing.

I am having the following error.

timestamp=2023-07-01T16:29:00.489Z level=ERROR thread=#zio-fiber-0 message="" cause="Exception in thread "zio-fiber-4" java.lang.ClassNotFoundException: zio.lambda.example.SimpleHandler$
at java.net.URLClassLoader.findClass(URLClassLoader.java:382)
at java.lang.ClassLoader.loadClass(ClassLoader.java:424)
at java.lang.ClassLoader.loadClass(ClassLoader.java:357)
at java.lang.Class.forName0(Native Method)
at java.lang.Class.forName(Class.java:348)
at zio.lambda.internal.LambdaLoaderLiveCommon.$anonfun$loadLambda$2(LambdaLoaderLive.scala:29)
at zio.ZIOCompanionVersionSpecific.$anonfun$attempt$1(ZIOCompanionVersionSpecific.scala:100)
at zio.lambda.internal.ZLambdaAppReflective.run(ZLambdaAppReflective.scala:15)
at zio.lambda.internal.ZLambdaAppReflective.run(ZLambdaAppReflective.scala:16)

I saw in a separate issue from @heaven-born that similar issue has arisen and have successfully resolved the issue. May I get help from you guys?...

          I managed to configure the env for the testing, but looks like something is not 100% right, because it `ZLambdaAppReflective` throws ` java.lang.ClassNotFoundException: zio.lambda.example.SimpleHandler$` and I can't figure out why. May I ask you to check out my branch, run it and figure out what is happening?  

ZLambdaAppReflective is now switched to the new app structure, so If you build with universal:packageBin the new approach will be used.

Originally posted by @heaven-born in #197 (comment)

@heaven-born
Copy link
Contributor

@Isaacwhyuenac I can't remember what exactly was wrong, but I remember I spent a significant amount of time trying to figure out how to deploy it to aws properly.
Maybe this comment will help: #135 (comment)

@Isaacwhyuenac
Copy link
Author

Thx @heaven-born for the quick reply. On my side, the same error persists even though I build the jar/zip with corretto64-11.0.19 on osx Apple silicon.

timestamp=2023-07-01T18:10:00.715Z level=ERROR thread=#zio-fiber-0 message="" cause="Exception in thread "zio-fiber-4" java.lang.ClassNotFoundException: zio.lambda.example.SimpleHandler$
at java.net.URLClassLoader.findClass(URLClassLoader.java:382)
at java.lang.ClassLoader.loadClass(ClassLoader.java:424)
at java.lang.ClassLoader.loadClass(ClassLoader.java:357)
at java.lang.Class.forName0(Native Method)
at java.lang.Class.forName(Class.java:348)
at zio.lambda.internal.LambdaLoaderLiveCommon.$anonfun$loadLambda$2(LambdaLoaderLive.scala:29)
at zio.ZIOCompanionVersionSpecific.$anonfun$attempt$1(ZIOCompanionVersionSpecific.scala:100)
at zio.lambda.internal.ZLambdaAppReflective.run(ZLambdaAppReflective.scala:15)
at zio.lambda.internal.ZLambdaAppReflective.run(ZLambdaAppReflective.scala:16)
at zio.lambda.internal.ZLambdaAppReflective.run(ZLambdaAppReflective.scala:25)"
START RequestId: ccf3ed13-072f-4ead-92f0-7bbc937f6844 Version: $LATEST
2023-07-01T18:10:03.950Z ccf3ed13-072f-4ead-92f0-7bbc937f6844 Task timed out after 3.11 seconds

END RequestId: ccf3ed13-072f-4ead-92f0-7bbc937f6844
REPORT RequestId: ccf3ed13-072f-4ead-92f0-7bbc937f6844	Duration: 3110.90 ms	Billed Duration: 3000 ms	Memory Size: 128 MB	Max Memory Used: 20 MB

@heaven-born
Copy link
Contributor

@Isaacwhyuenac did you follow the steps this way #197 (comment) ?

  • Create a lambda function based on Java-11 Coretto JVM runtime (or another jvm you like)
  • Change the runtime to "Custom Runtime"

@Isaacwhyuenac
Copy link
Author

Isaacwhyuenac commented Jul 1, 2023

Thx @heaven-born Yes, I follow it. 😢
Screenshot 2023-07-02 at 03 29 13
Screenshot 2023-07-02 at 03 30 11
Screenshot 2023-07-02 at 03 31 55

zio-lambda-1.0.4.zip

I renamed the .jar to .zip to bypass github file extension restriction.... == zio-lambda-example.jar
zio-lambda-example.zip

@heaven-born
Copy link
Contributor

Can't unzip your zio-lambda-example.jar for some reason to check the content, but let me ask something.
Do you deploy both function and layer files? You should deploy only layer zip file. Just check if the layer zip contains dev.zio.zio-lambda-example-1...jar in libs director, bin directory and the bootstrap file.

And in my case the "compatible runtime" was "provided" instead of java11.

@heaven-born
Copy link
Contributor

The layer is basically your function, you should not provide separate code for the function.

@Isaacwhyuenac
Copy link
Author

Isaacwhyuenac commented Jul 2, 2023

In my lambda layer zio-lambda-1.0.4.zip, There is no zio-lambda-example-1...jar inside.

Result of sbt "zio-lambda / universal:packageBin"

Screenshot 2023-07-02 at 12 34 22

Now I have the runtime as "compatible runtime" and is shown as provided.

Screenshot 2023-07-02 at 12 39 17

Let me reupload my lambda code here

zio-lambda-example.jar.zip

The layer is basically your function, you should not provide separate code for the function.

This is quite contrary to my understanding of the lambda layer and business knowledge separation. Do you have a working example and upload the jar and the screenshots for my reference?? Thx

@heaven-born
Copy link
Contributor

heaven-born commented Jul 2, 2023

No, I have only working project configured to be compiled using graalvm. The is no need in layers in this case.

I remember I was also confused about the code separation, but as I remember this is how I managed to make it works. I needed this working only to test my PR, so not much memory about this issue left in my head.

Maybe the way I made is working is not canonical way or I forgot something, but what I can remember is that there must be only the layer. However, I don’t understand why your universal package doesn’t contain this jar. I will try to reproduce it today if I have some extra time.

@heaven-born
Copy link
Contributor

the universal package under lambda-example contains the example jar. You can try to use it as a layer.
The code separation is still a question but looks like this is how I made the function work.
The package under lambda-example also contains bin directory, so my guess is that it is designed to be used this way.

But I would also love to know the canonical way of doing this.

@Isaacwhyuenac
Copy link
Author

Confirmed the universal package under lambda-example contains the example jar, but it is not working.

Confirm the graalvm approach does work.

Thx @heaven-born Yes, I follow it. 😢 Screenshot 2023-07-02 at 03 29 13 Screenshot 2023-07-02 at 03 30 11 Screenshot 2023-07-02 at 03 31 55

zio-lambda-1.0.4.zip

I renamed the .jar to .zip to bypass github file extension restriction.... == zio-lambda-example.jar zio-lambda-example.zip

Maybe we need the input from @jrmsamson as I followed his approach #197 (comment) to test the non-graalvm and not working. His screenshots do look working perfectly with

sbt "zio-lambda / universal:packageBin"
sbt "zio-lambda-example / assembly"

@heaven-born
Copy link
Contributor

I can give you my working example of the layer that I downloaded from the aws.
test-0e2b500e-32ce-487a-9201-c498c119cb86.zip

If you deploy it and run a test using this json it will work:

{
  "message": "value1"
}

Unfortunately, I don't remember how I made it. But it was something to do with z-lambda-app-reflective executable file that my bootstrap is poinint to.

@heaven-born
Copy link
Contributor

there is a good chance that I manually added the class zio.lambda.example.SimpleHandler to the 'lambda' project just for testing purposes because I don't see the zio-lambda-example-1...jar there.

@jrmsamson
Copy link
Contributor

jrmsamson commented Jul 2, 2023

Hi @Isaacwhyuenac @heaven-born,

First of all apologies for the lack of documentation. I'm aware that It can be confusing but I'll try to document this to make it easier for new users to start using zio-lambda.

What I normally do to start using zio-lambda as a layer is I go to the root of the project and run the following to generate the zip that needs to be uploaded to AWS to create the layer. (My intention is to include it in the README so people can just download it without running this)

sbt "zio-lambda / universal:packageBin"

This is the file that got generated from the last version zio-lambda-1.0.4.zip

Afterwards, with the help of aws-cli I connect to my account and I run

aws lambda publish-layer-version --layer-name zio-lambda-runtime --zip-file fileb://zio-lambda-1.0.4.zip

The only thing left is to upload your lambda function implemented with zio-lambda and select the custom layer you just uploaded.

You can use this to test the layer. zio-lambda-example.zip

(Edit: I just tested it and it works fine for me)

@Isaacwhyuenac
Copy link
Author

resolved Thx @jrmsamson @heaven-born

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants