我订阅了一个CloudWatch的日志流的拉姆达。这一切工作tickety嘘即,当日志流写入到拉姆达收到通知。现在,有接收登陆或日志与通知的部分内容的方式还是我接下来要查询的日志流,以争取我需要的信息?
问候
安格斯
是的你可以。以下是如何用Node.js的LAMBDA做到这一点:
var zlib = require('zlib');
exports.handler = function(input, context) {
// decode input from base64
var zippedInput = new Buffer.from(input.awslogs.data, 'base64');
// decompress the input
zlib.gunzip(zippedInput, function(error, buffer) {
if (error) { context.fail(error); return; }
// parse the input from JSON
var payload = JSON.parse(buffer.toString('utf8'));
// ignore control messages
if (payload.messageType === 'CONTROL_MESSAGE') {
return null;
}
// print the timestamp and message of each log event
payload.logEvents.forEach(function(logEvent) {
console.log(logEvent.timestamp + ' ' + logEvent.message);
});
});
};