jeremydaly / lambda-warmer

A module to optimize AWS Lambda function cold starts
MIT License
525 stars 55 forks source link

Lambda gets invoked multiple times #7

Closed geetchoubey closed 5 years ago

geetchoubey commented 5 years ago

Hi We have multiple lambdas and we are using terraform to deploy it so the input as an event that I am providing is {"warmer": true, "functions": ["lambda_b", "lambda_c",...]} When I am using a lambda (say Lambda_A) function so as to warm other lambdas at a rate of 15 minutes from the scheduler, I can see that the lambda is being invoked every 10 seconds. I believe the library is already invoking itself (using aws-sdk) and also the other lambdas.

Lambda_A code: ` if (await warmer(event)) {

  logger.info('Warmed lambda warmer itself!');

  if (!event.functions) return 'No functions to warm up!';

  let lambda = new AWS.Lambda();

  let warmers = event.functions.map(functionName => {

    let params = {

      FunctionName: functionName ,

      InvocationType: 'Event',

      LogType: 'Tail',

      Payload: Buffer.from(JSON.stringify(event))

    }

    return lambda.invoke(params).promise();
  });

  try { await Promise.all(warmers)} catch (e) {

    logger.info('Error while warming some lambdas');

    logger.error(e);

  }

  logger.info('Warmed all lambdas');

  return 'Warming done!';

}

return 'Nothing more to do here!';`

Lambda_B code: if (await warmer(event, { log: false })) { logger.info('Warmed!!'); return 'Warmed'; } // Rest of the implementation Cloudwatch logs

aws-sdk: 2.414.0

geetchoubey commented 5 years ago

Turns out this issue was due to a million requests that were performed earlier and were being served even after new functions were deployed. Thanks a ton J.

jeremydaly commented 5 years ago

Glad you figured it out!