I built two project and added layers to AWS Lamba successfully.
And my functions use these two layers.
This is my structure of layer
When I execute the function, an error happened:
java.lang.NoClassDefFoundError
I know the location of the layer is inside/opt, but how can I use the layer's library in functions?
Anyone trying to figure out how to copy your dependencies (.jar) into java/lib
directory, this is maven snippet from a project -
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>${maven.compiler.plugin.version}</version>
<configuration>
<source>${maven.compiler.source}</source>
<target>${maven.compiler.target}</target>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-dependency-plugin</artifactId>
<version>2.8</version>
<executions>
<execution>
<id>copy-dependencies</id>
<phase>prepare-package</phase>
<goals>
<goal>copy-dependencies</goal>
</goals>
<configuration>
<outputDirectory>${project.build.directory}/classes/java/lib</outputDirectory>
<includeScope>runtime</includeScope>
</configuration>
</execution>
</executions>
</plugin></plugins></build>
Hope this will come handy to someone
You should locate the files into a folder, in according to the language:
Node.js –> nodejs/node_modules or nodejs/node8/node_modules (NODE_PATH)
Python – python -> python/lib/python3.7/site-packages (site
directories)
Java –> java/lib (classpath)
Ruby –> ruby/gems/2.5.0 (GEM_PATH), ruby/lib (RUBY_LIB)
Or default All –> bin (PATH), lib (LD_LIBRARY_PATH)
For more details see: https://docs.aws.amazon.com/en_us/lambda/latest/dg/configuration-layers.html#configuration-layers-path
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With