dougmoscrop / serverless-http

Use your existing middleware framework (e.g. Express, Koa) in AWS Lambda 🎉
Other
1.72k stars 166 forks source link

scheduled event data access/logging #104

Closed adamwilbert closed 5 years ago

adamwilbert commented 5 years ago

I am using scheduled events, in addition to normal http requests served through serverless-http, but I don't seem to have access to logging or anything else when the event fires.

For example:

      - schedule:
          name: ${self:service}-${self:provider.stage}-func-warmer
          rate: rate(5 minutes)
          enabled: true
          input:
            warmer: true
            concurrency: 1

with an immediate console.log(req, res, next) in the handler results in logging through cloudwatch similar to

START RequestId:  Version: $LATEST
END RequestId: 
REPORT RequestId:   Duration: 1.61 ms   Billed Duration: 100 ms     Memory Size: 1024 MB    Max Memory Used: 92 MB

Any thoughts on why that might be?

dougmoscrop commented 5 years ago

I would expect the request-response to be failing and returning lke "500" or something (not that cloudwatch cares)

If you do this you need to intercept:

const serverless = require('severless-http')
const app = express();
const handle = serverless(app);
module.exports = (event, context) => {
  // not sure if this is right, but there's a property on the event
  if (event.source === 'warmup') {
    return ..
  }
  return handle(event, context);
}
adamwilbert commented 5 years ago

That's pretty close to perfect, thank you!