How to do it...

  1. Create the project from the following template:
$ sls create --template-url https://github.com/danteinc/js-cloud-native-cookbook/tree/master/ch7/event-metrics --path cncb-event-metrics
  1. Navigate to the cncb-event-metrics directory with cd cncb-event-metrics.
  2. Review the file named serverless.yml.
  3. Review the file named handler.js with the following content:
module.exports.listener = (event, context, cb) => {  _(event.Records)    .map(recordToUow)    .tap(count)    ...    .collect().toCallback(cb);};const count = (uow) => {  const tags = [    `account:${process.env.ACCOUNT_NAME}`,    `region:${uow.record.awsRegion}`,    `stream:${uow.record.eventSourceARN.split('/')[1]}`,    `shard:${uow.record.eventID.split('-')[1].split(':')[0]}`, `source:${uow.event.tags ...

Get JavaScript Cloud Native Development Cookbook now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.