使用 lambda 函数将数据发送到 kinesis 流(在不同的 AWS 账户中)

P p*_*ker 5 amazon-web-services amazon-kinesis aws-lambda

我有一个写入运动流的 lambda 函数。但现在,我想写入属于不同 AWS 账户的 kinesis 流。假设我拥有所有必要的跨帐户权限,我如何将数据发送到该流?调用kinesis构造函数或putRecord函数时,应该如何更改参数?

Mai*_*KaY 1

首先您需要配置 Kinesis 实例:

(我选择Javascript作为例子)

var kinesis = new AWS.Kinesis({
    accessKeyId: 'XXX',
    secretAccessKey: 'YYY',
    region: 'eu-west-1',
    apiVersion: '2013-12-02'
});
Run Code Online (Sandbox Code Playgroud)

有关更多信息,请查看构建 Kinesis 对象

要写入/放置记录,请使用以下命令

var params = {
    Data: new Buffer('...') || 'STRING_VALUE', /* required */
    PartitionKey: 'STRING_VALUE', /* required */
    StreamName: 'STRING_VALUE', /* required */
    ExplicitHashKey: 'STRING_VALUE',
    SequenceNumberForOrdering: 'STRING_VALUE'
};
kinesis.putRecord(params, function (err, data) {
    if (err) console.log(err, err.stack); // an error occurred
    else     console.log(data);           // successful response
});
Run Code Online (Sandbox Code Playgroud)

有关更多信息,请查看调用 putRecord 操作