serverless-plugin-simulate
serverless-plugin-simulate copied to clipboard
java.lang.ClassNotFoundException when trying to run a JVM project
This is a Bug Report
Description
After running sls simulate apigateway -p 5000
and curl
ing my API, I see this error in the sls console:
START RequestId: 6a51ae52-d900-4713-92f4-13f005d9b49a Version: $LATEST
java.lang.ClassNotFoundException: twilioDatasource.Incoming
at java.net.URLClassLoader.findClass(URLClassLoader.java:381)
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)
END RequestId: 6a51ae52-d900-4713-92f4-13f005d9b49a
REPORT RequestId: 6a51ae52-d900-4713-92f4-13f005d9b49a Duration: 1.78 ms Billed Duration: 100 ms Memory Size: 1024 MB Max Memory Used: 5 MB
Serverless: Mapping response
Serverless: Error returning error response for /datasources/twilio.recv
Serverless: {}
Serverless: RangeError: Invalid status code: undefined
at ServerResponse.writeHead (_http_server.js:190:11)
at ServerResponse.writeHead (/home/enolan/code/signalvine/scala-lambda-poc/node_modules/on-headers/index.js:55:19)
at ServerResponse._implicitHeader (_http_server.js:181:8)
at ServerResponse.end (_http_outgoing.js:757:10)
at ServerResponse.send (/home/enolan/code/signalvine/scala-lambda-poc/node_modules/express/lib/response.js:221:10)
at respond (/home/enolan/code/signalvine/scala-lambda-poc/node_modules/serverless-plugin-simulate/lib/integration/middleware.js:14:9)
at integration.event.then.then.catch.then.response (/home/enolan/code/signalvine/scala-lambda-poc/node_modules/serverless-plugin-simulate/lib/integration/middleware.js:35:23)
at tryCatcher (/home/enolan/code/signalvine/scala-lambda-poc/node_modules/bluebird/js/release/util.js:16:23)
at Promise._settlePromiseFromHandler (/home/enolan/code/signalvine/scala-lambda-poc/node_modules/bluebird/js/release/promise.js:512:31)
at Promise._settlePromise (/home/enolan/code/signalvine/scala-lambda-poc/node_modules/bluebird/js/release/promise.js:569:18)
at Promise._settlePromise0 (/home/enolan/code/signalvine/scala-lambda-poc/node_modules/bluebird/js/release/promise.js:614:10)
at Promise._settlePromises (/home/enolan/code/signalvine/scala-lambda-poc/node_modules/bluebird/js/release/promise.js:693:18)
at Async._drainQueue (/home/enolan/code/signalvine/scala-lambda-poc/node_modules/bluebird/js/release/async.js:133:16)
at Async._drainQueues (/home/enolan/code/signalvine/scala-lambda-poc/node_modules/bluebird/js/release/async.js:143:10)
at Immediate.Async.drainQueues (/home/enolan/code/signalvine/scala-lambda-poc/node_modules/bluebird/js/release/async.js:17:14)
at runCallback (timers.js:789:20)
at tryOnImmediate (timers.js:751:5)
at processImmediate [as _immediateCallback] (timers.js:722:5)
POST /datasources/twilio.recv 500 991.749 ms - 2025
Expected behavior is to run the function without error.
My guess is it's not finding the fat JAR file my project builds. I have this section in serverless.yml
:
package:
artifact: target/scala-2.12/hello.jar
From the docker-lambda
README, "The directory must be laid out in the same way the Lambda zip file is". I'm going to try and put together a PR fixing this.
Additional Data
- Serverless Framework Version you're using: 1.26.0
- Serverless Docker Plugin Version you're using: 0.0.17
- Operating System: Ubuntu Linux 17.10
- Stack Trace: see above
- Provider Error messages: N/A
Here's my full serverless.yml
:
service: scala-lambda-poc
provider:
name: aws
runtime: java8
stage: dev
region: us-east-1
package:
artifact: target/scala-2.12/hello.jar
functions:
twilioMessageRecv:
handler: twilioDatasource.Incoming
events:
- http:
method: post
path: datasources/twilio.recv
plugins:
- serverless-plugin-simulate