AWS Kinesis Firehose 未响应 Lambda
AWS Kinesis Firehose not responding to Lambda
这是 Lambda 代码:
const AWS = require('aws-sdk');
var firehose = new AWS.Firehose({ region: 'ap-southeast-2' });
exports.handler = async (event, context) => {
var params = {
DeliveryStreamName: 'TestStream',
Record: {
Data: 'test data'
}
};
console.log('params', params);
firehose.putRecord(params, function (err, data) {
if (err) console.log(err, err.stack); // an error occurred
else console.log('Firehose Successful', data); // successful response
});
}
政策是:
{
"Version": "2012-10-17",
"Statement": [
{
"Effect": "Allow",
"Action": [
"firehose:DeleteDeliveryStream",
"firehose:PutRecord",
"firehose:PutRecordBatch",
"firehose:UpdateDestination"
],
"Resource": [
"arn:aws:firehose:ap-southeast-2:xxxxxxxxxxxxx:deliverystream/TestStream"
]
}
]
}
我已经完全删除了所有其他内容。我在 cloudwatch 中看到的响应是:
2020-11-05T18:08:17.564+13:00 START RequestId: 3bed96b1-54af-4b08-bc06-be3732bba9ea Version: $LATEST
2020-11-05T18:08:17.568+13:00 2020-11-05T05:08:17.567Z 3bed96b1-54af-4b08-bc06-be3732bba9ea INFO params { DeliveryStreamName: 'TestStream', Record: { Data: <Buffer 74 65 73 74 20 64 61 74 61> } }
2020-11-05T18:08:17.621+13:00 END RequestId: 3bed96b1-54af-4b08-bc06-be3732bba9ea
2020-11-05T18:08:17.621+13:00 REPORT RequestId: 3bed96b1-54af-4b08-bc06-be3732bba9ea Duration: 57.38 ms Billed Duration: 100 ms Memory Size: 960 MB Max Memory Used: 85 MB Init Duration: 399.22 ms
所以,执行到达消防水管线,直接越过它们,什么都不做...
由于您使用的是 async handler,我认为问题是您的函数在 firehose 代码有机会 运行.
之前完成
纠正此问题的一种方法是使用 Promise
,如 AWS docs 所示。例如:
const AWS = require('aws-sdk');
var firehose = new AWS.Firehose({ region: 'ap-southeast-2' });
exports.handler = async (event, context, callback) => {
const promise = new Promise(function(resolve, reject) {
var params = {
DeliveryStreamName: 'TestStream',
Record: {
Data: 'test data'
}
};
console.log('params', params);
firehose.putRecord(params, function (err, data) {
if (err) console.log(err, err.stack); // an error occurred
else console.log('Firehose Successful', data); // successful response
});
})
return promise;
};
以上更改仅供参考,因此可能仍需要进行一些调整。
这是 Lambda 代码:
const AWS = require('aws-sdk');
var firehose = new AWS.Firehose({ region: 'ap-southeast-2' });
exports.handler = async (event, context) => {
var params = {
DeliveryStreamName: 'TestStream',
Record: {
Data: 'test data'
}
};
console.log('params', params);
firehose.putRecord(params, function (err, data) {
if (err) console.log(err, err.stack); // an error occurred
else console.log('Firehose Successful', data); // successful response
});
}
政策是:
{
"Version": "2012-10-17",
"Statement": [
{
"Effect": "Allow",
"Action": [
"firehose:DeleteDeliveryStream",
"firehose:PutRecord",
"firehose:PutRecordBatch",
"firehose:UpdateDestination"
],
"Resource": [
"arn:aws:firehose:ap-southeast-2:xxxxxxxxxxxxx:deliverystream/TestStream"
]
}
]
}
我已经完全删除了所有其他内容。我在 cloudwatch 中看到的响应是:
2020-11-05T18:08:17.564+13:00 START RequestId: 3bed96b1-54af-4b08-bc06-be3732bba9ea Version: $LATEST
2020-11-05T18:08:17.568+13:00 2020-11-05T05:08:17.567Z 3bed96b1-54af-4b08-bc06-be3732bba9ea INFO params { DeliveryStreamName: 'TestStream', Record: { Data: <Buffer 74 65 73 74 20 64 61 74 61> } }
2020-11-05T18:08:17.621+13:00 END RequestId: 3bed96b1-54af-4b08-bc06-be3732bba9ea
2020-11-05T18:08:17.621+13:00 REPORT RequestId: 3bed96b1-54af-4b08-bc06-be3732bba9ea Duration: 57.38 ms Billed Duration: 100 ms Memory Size: 960 MB Max Memory Used: 85 MB Init Duration: 399.22 ms
所以,执行到达消防水管线,直接越过它们,什么都不做...
由于您使用的是 async handler,我认为问题是您的函数在 firehose 代码有机会 运行.
之前完成纠正此问题的一种方法是使用 Promise
,如 AWS docs 所示。例如:
const AWS = require('aws-sdk');
var firehose = new AWS.Firehose({ region: 'ap-southeast-2' });
exports.handler = async (event, context, callback) => {
const promise = new Promise(function(resolve, reject) {
var params = {
DeliveryStreamName: 'TestStream',
Record: {
Data: 'test data'
}
};
console.log('params', params);
firehose.putRecord(params, function (err, data) {
if (err) console.log(err, err.stack); // an error occurred
else console.log('Firehose Successful', data); // successful response
});
})
return promise;
};
以上更改仅供参考,因此可能仍需要进行一些调整。