If you run serverless offline with the serverless.yml file below, and the Java package contains many class files, serverless offline fails with the following message when invoking the GET endpoint (the name of the class file is random):
× EMFILE: too many open files, open 'C:\Users\...\Documents\BugServerlessOffline\.serverless-offline\services\bugserverlessoffline\hello\efc4c712-3754-45b6-a153-6f14049501d3\code\software\amazon\awssdk\services\route53\model\UpdateHostedZoneCommentRequest$1.class'
serverless offline fails while unpacking the hello-dev.jar-file to the .serverless-offline folder. Either while extracting there are too many files opened at the same moment or the files are not closed.
I fixed this problem by modifying serverless-offline\src\lambda\LambdaFunction.js as follows:
Added import: import { writeFileSync } from 'fs'
In the function extractArtifact I replaced the line return writeFile(join(this.#codeDir, filename), fileData, { by return writeFileSync(join(this.#codeDir, filename), fileData, {
Bug Report
Current Behavior
If you run
serverless offline
with theserverless.yml
file below, and the Java package contains many class files,serverless offline
fails with the following message when invoking the GET endpoint (the name of the class file is random):The serverless.yml file is as follows:
serverless offline
fails while unpacking thehello-dev.jar
-file to the.serverless-offline
folder. Either while extracting there are too many files opened at the same moment or the files are not closed.I fixed this problem by modifying
serverless-offline\src\lambda\LambdaFunction.js
as follows:import { writeFileSync } from 'fs'
extractArtifact
I replaced the linereturn writeFile(join(this.#codeDir, filename), fileData, {
byreturn writeFileSync(join(this.#codeDir, filename), fileData, {
Here is the patch for these changes: LambdaFunction.js.patch
Sample Code
I've created a simple sample application with
serverless create --template aws-java-maven
, and added a lot of dependencies to thepom.xml
file:I then also modified the
serverless.yml
slightly (addedGET /hello
endpoint).Here is the complete sample application: BugServerlessOffline.zip
Expected behavior/code
Serverless offline shouldn't fail.
Environment
serverless
version: 3.30.1serverless-offline
version: 12.0.4node.js
version: v18.14.2OS
: Windows 10Possible Solution
See above.
Additional context/Screenshots
None.