我正在尝试使用节点 JS 中的 Lambda 函数从 kinesis 分析中读取数据,当我尝试对其进行解码时,我正在以编码格式获取数据我没有得到任何输出。
console.log('Loading function');
const zlib = require('zlib');
exports.handler = async (event, context) => {
let success = 0;
let failure = 0;
const output = event.records.map((record) => {
// let compressedData = zlib.deflate(record['data'])
try {
// console.log(compressedData.toString('ascii'))
console.log('saran100000')
var compressedData = zlib.deflate(record['data'])
console.log('saran')
console.log(record.data)
console.log(compressedData)
var compAndToString =zlib.deflate(record['data']).toString('utf8')
console.log('saran1')
console.log(compAndToString)
var compAndUncomp = zlib.inflate(zlib.deflate(record['data']))
console.log('saran2')
console.log(compAndUncomp)
var convertBackToString = zlib.inflate(zlib.deflate(record['data'])).toString('utf8')
console.log('saran3')
console.log(convertBackToString)
success++;
return {
recordId: record.recordId,
// data:result,
result: 'Ok'
};
} catch (err) {
console.log(err)
failure++;
return {
recordId: record.recordId,
result: 'DeliveryFailed',
};
}
});
console.log(`Successful delivered records ${success}, Failed delivered records ${failure}.`);
return { records: output };
};
我还尝试了以下链接中的代码 单击此处