juanjoDiaz / serverless-plugin-warmup

Keep your lambdas warm during winter. ♨
MIT License
1.11k stars 115 forks source link

warm up plugin webpack bundling issue #337

Closed Bhirahaspathi-Sairam closed 1 year ago

Bhirahaspathi-Sairam commented 1 year ago

I am using serverless warm up plugin in my project and it fails while bundling with webpack. I am not sure what the issue is.Below is the configs

 warmup:
    default:
      cleanFolder: false
      memorySize: 256
      name: ${self:service}-${self:custom.stage}-warmer

      events:
        - schedule: 'cron(0/5 8-17 ? * MON-FRI *)'
      timeout: 20
      verbose: true
      logRetentionInDays: 14
      prewarm: true
      concurrency: 5

I have enabled warmup at function specific level.

Here is the output from jenkins

WarmUp: Creating warmer "default" to warm up 5 functions

Bundling with Webpack...

ERROR in ../../../.warmup/default/index.js 6:12-45

Module not found: Error: Can't resolve '@aws-sdk/client-lambda' in '/.warmup/default'

Can anyone tell me why its happening

juanjoDiaz commented 1 year ago

Hi @Bhirahaspathi-Sairam,

You need to declare the warmup plugin after the webpack plugin to avoid it being transpiled as it is not needed.

Cheers!

andrzej-hanusek-tg commented 1 year ago

@juanjoDiaz I have declared warmup plugin after the webpack plugin but still getting this issue 🤔 .

juanjoDiaz commented 1 year ago

Hi @andrzej-hanusek-tg ,

I get a lot of these and it's always something to do with the different bundling pluging using different lifecycle hooks. Which also impacted by the order in which you declare the plugins.

I have no idea of which bundling plugin you are using, in which order you are declaring the plugins, which versions are you using, etc. So I need more context if you need help. A sample project where I can reproduce the issue is the faster way.

I can't do anything about webpack plugin lifecycle hook. You might want to install @aws-sdk/client-lambda as a dev dependency so webpack can do the bundling (even if warmup then ignores the bundled version of the lambda) or configure it as a external dependency that webpack should try to bundle as it is installed globally in the lambda.

andrzej-hanusek-tg commented 1 year ago

@juanjoDiaz Downgrading plugin to the 8.1.0 helps.

juanjoDiaz commented 1 year ago

That's because 8.2 changes the runtime of the plugin to node 18 which uses the new serverless SDK.

As said, you can add @aws-sdk/client-lambda as a dev dependency and the error should go away. However, the issue is still that the webpack plugin shouldn't be bundling the warmer lambda.