我试图通过lambda函数调用运动学。这是我的代码
const AWS = require( 'aws-sdk' );
AWS.config.update({ region: 'us-east-1' });
var firehose = new AWS.Firehose();
exports.handler = async (event,context,callback) => {
// TODO implement
const response = {
statusCode:200,
Name:event.Name,
Value:event.Value
};
const params = {
DeliveryStreamName: 'kinesis-fh-pika',
Record: { Data: new Buffer(JSON.stringify(response)) }
};
firehose.putRecord(params, (err, data) => {
if (err) console.log(err, err.stack); // an error occurred
else console.log(data);
});
};
这是我的活动
{
"Name": "sara",
"Value": 10
}
我在lambda中没有任何错误。它始终将响应显示为null
。我什至尝试启用日志,但没有发现任何奇怪的行为。
我错过了什么吗?
谢谢
答案 0 :(得分:1)
它返回“ null”,因为您的Lambda函数未返回任何东西。
尝试
const AWS = require( 'aws-sdk' );
AWS.config.update({ region: 'us-east-1' });
var firehose = new AWS.Firehose();
exports.handler = async (event) => {
// TODO implement
const response = {
statusCode:200,
Name:event.Name,
Value:event.Value
};
const params = {
DeliveryStreamName: 'kinesis-fh-pika',
Record: { Data: new Buffer(JSON.stringify(response)) }
};
firehose.putRecord(params, (err, data) => {
if (err) {
console.log(err, err.stack);
} // an error occurred
else {
console.log(data);
}
return response;
});
};
答案 1 :(得分:-1)
我可以解决我的问题。我只想念一个callback
电话。看来putRecord仅在获得一些响应回调时才发生。这是工作代码
const AWS = require( 'aws-sdk' );
AWS.config.update({ region: 'us-east-1' });
var firehose = new AWS.Firehose();
exports.handler = async (event,context,callback) => {
// TODO implement
const response = {
statusCode:200,
Name:event.Name,
Value:event.Value
};
const params = {
DeliveryStreamName: 'kinesis-fh-pika',
Record: { Data: new Buffer(JSON.stringify(response)) }
};
firehose.putRecord(params, (err, data) => {
if (err) console.log(err, err.stack); // an error occurred
else console.log(data);
});
callback(null,"success");
};