serverless-plugin-warmup: Unable to import module

Hi,

the plugin does not work for me, from CloudWatch Logs:

Unable to import module '_warmup/index': Error at Function.Module._resolveFilename (module.js:469:15) at Function.Module._load (module.js:417:25) at Module.require (module.js:497:17) at require (internal/module.js:20:19)
Unable to import module '_warmup/index': Error
at Function.Module._resolveFilename (module.js:469:15)
at Function.Module._load (module.js:417:25)
at Module.require (module.js:497:17)
at require (internal/module.js:20:19)

Does it only work if you are using nodejs runtime?

About this issue

  • Original URL
  • State: closed
  • Created 7 years ago
  • Reactions: 1
  • Comments: 34 (16 by maintainers)

Most upvoted comments

Actually, just created a PR in Serverless that fix the root cause of this issue (the individually config is not honored when there is a package: artifact: ... set up at service level).

Let’s see if it can get merge and we won’t need to workaround the issue 🙂

So how did you guys resolve the issue? Even with cleanFolder set false the issue still remains.

If anyone other (next to me) is struggling over this issue and has problems solving it with the above discussion:

Issue

When you install the plugin via npm and you run sls package, a directory called ‘_warmup’ within your service root will be created. If you now run sls deploy, the (in serverless.yml) specified artifact (package: artifact: artifactpath) will be uploaded to the deploy bucket on aws. But the _warumup dir which consists of the warump function written in javascript is ignored. This causes the “module not found” error in CloudWatch

The solution

You have to move the _warmup dir into your resources folder (src.main.resources) of your service. This folder will be unpacked by maven and will be added to the root of the .jar. AWS will search within this jar for a dir ‘_warmup’ which consists of a index.js.

In commands

All commands are from the root of your service

sls package

‘_warmup’ will be created

mv _warmup src/main/resources/

move the folder to your resources dir

mvn clean package

package the artifact

sls deploy

deploys the jar

and here is my serverless.yml conf for the plugin

custom:
  ...
  warmup:
    memorySize: 256
    schedule: 'cron(0/5 8-17 ? * MON-FRI *)' # Run WarmUP every 5 minutes Mon-Fri between 8:00am and 5:55pm (UTC)
    timeout: 20
    cleanFolder: false
    prewarm: true # Run WarmUp immediately after a deployment
    tags:
      Project: **
      Owner: **