I have created AWS Lambda function and now I am trying to setup deployment on AWS. I have created buildspec.yml file with following content:
version: 0.1
phases:
build:
commands:
- echo Entering build phase...
- echo Build started on `date`
- mvn package shade:shade
- mv target/classes/* .
- rm -rf target src buildspec.yml pom.xml
- aws cloudformation package --template template.json --s3-bucket $S3_BUCKET --output-template template-export.json
artifacts:
type: zip
files:
- template-export.json
Now when I push my code to AWS CodeCommit, build process is run successfully but in output s3 bucket there is output file of only 130 kb. This means that my dependencies are missing from created package, and when I try running my Lambda I got following error:
Error loading class com.test.handler: org/apache/log4j/Logger: class java.lang.NoClassDefFoundError
In my pom.xml file I added shade plugin:
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-shade-plugin</artifactId>
<version>2.3</version>
<configuration>
<createDependencyReducedPom>false</createDependencyReducedPom>
</configuration>
<executions>
<execution>
<phase>package</phase>
<goals>
<goal>shade</goal>
</goals>
</execution>
</executions>
</plugin>
When I run command mvn package
on my PC everything is OK and I get jar file containing all my dependencies (size is little over 10mb) and if I manually deploy this jar to AWS lambda function everything is working as expected.
I also tried following this tutorial: Link, but nothing changed.
Can someone please help, I really don't know what I am missing here :/