Skip to content

Instantly share code, notes, and snippets.

@Mikulas
Last active April 14, 2017 10:38
Show Gist options
  • Save Mikulas/a06ab9090e0ebb106b16affa59540488 to your computer and use it in GitHub Desktop.
Save Mikulas/a06ab9090e0ebb106b16affa59540488 to your computer and use it in GitHub Desktop.
AWS Lambda CloudWatch Stream processor
var Buffer = require('buffer').Buffer;
var zlib = require("zlib");
exports.handler = (event, context, callback) => {
var rawGzEnc = event.awslogs.data;
var rawGz = Buffer.from(rawGzEnc, 'base64');
var raw = zlib.gunzipSync(rawGz).toString();
var data = JSON.parse(raw);
console.log(data);
// TODO process data
};
@Mikulas
Copy link
Author

Mikulas commented Apr 14, 2017

{ messageType: 'DATA_MESSAGE',
  owner: '123456789123',
  logGroup: 'testLogGroup',
  logStream: 'testLogStream',
  subscriptionFilters: [ 'testFilter' ],
  logEvents: [ { id: 'eventId1',
       timestamp: 1440442987000,
       message: '[ERROR] First test message' },
     { id: 'eventId2',
       timestamp: 1440442987001,
       message: '[ERROR] Second test message' } ] }

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment