Serverless framework WarmUp plugin not being called

1.1k views Asked by At

I tried to integrate the WarmUp serverless plugin into my project. However, I believe that it is not working. I see no invocations from WarmUp in the lambda’s CloudWatch log group, and lambda does need warmup time after being idle for a bit.

My configuration is below:

service: ${file(./${env:DEPLOY_FILE_NAME}):service}

provider:
  name: aws
  custom:
    roleName: ${file(./${env:DEPLOY_FILE_NAME_STAGE}):roleName}
    profileName: ${file(./${env:DEPLOY_FILE_NAME_STAGE}):profileName}
    bundle:
      ignorePackages:
        - pg-native
    warmup:
      enabled: true
      events:
        - schedule: rate(5 minutes)
      prewarm: true
  plugins:
    - pluginHandler
    - serverless-plugin-warmup
  runtime: nodejs12.x
  iamRoleStatements:
    - Effect: 'Allow'
      Action:
        - 'lambda:InvokeFunction'
      Resource:
      - Fn::Join:
        - ':'
        - - arn:aws:lambda
          - Ref: AWS::Region
          - Ref: AWS::AccountId
          - function:${self:service}-${opt:stage, self:provider.stage}-*
  cfLogs: true
  stage: ${file(./${env:DEPLOY_FILE_NAME_STAGE}):stage}
  region: ${file(./${env:DEPLOY_FILE_NAME_STAGE}):region}
  memorySize: ${file(./${env:DEPLOY_FILE_NAME_STAGE}):memorySize}
  timeout: ${file(./${env:DEPLOY_FILE_NAME_STAGE}):timeout}
  keepWarm: false
  useApigateway: true

package:
  exclude:
    ${file(./${env:DEPLOY_FILE_NAME}):exclude}

functions:
  lambdaHandler:
    handler: ${file(./${env:DEPLOY_FILE_NAME_STAGE}):handler}
    events:
      ${file(./${env:DEPLOY_FILE_NAME}):events}
    warmup:
      enabled: true

The lambda code:

const awsLambdaFastify = require('aws-lambda-fastify');
const app = require('./index');

const proxy = awsLambdaFastify(app);

const fastify = (event, context, callback) => {
  context.callbackWaitsForEmptyEventLoop = false;
  proxy(event, context, callback);
};

const warm = func => (event, context, callback) => {
  if (event.source === 'serverless-plugin-warmup') {
    return callback(null, 'Lambda is warm!');
  }

  return func(event, context, callback);
};

exports.handler = warm(fastify);

Is there something that I could check? Any suggestions/directions are greatly appreciated.

Thank you

1

There are 1 answers

0
elbik On BEST ANSWER

First of all, please move out the plugins from provider

plugins:
    - serverless-plugin-warmup
provider:
    ...