[英]Sending data to kinesis stream (in different AWS account) using lambda function
I have a lambda function that writes to a kinesis stream. 我有一个lambda函数,可以写入运动流。 But now, I want to write to a kinesis stream which belongs to a different AWS account.
但是现在,我想写一个属于另一个AWS账户的运动流。 Assuming I have all the necessary cross account permissions, how can I send data to this stream?
假设我拥有所有必需的交叉帐户权限,如何将数据发送到此流? How should I change the parameters when I call the kinesis constructor or the putRecord function?
调用kinesis构造函数或putRecord函数时应如何更改参数?
There is the method above which would technically work, however hardcoding creds or even configuring creds into a lambda seems a bit extraneous to me since lambdas themselves require that you have a role. 上面有一种方法在技术上可行,但是对代码进行硬编码甚至将凭据配置为lambda对我来说似乎有点多余,因为lambda本身要求您扮演角色。 What you need to do is create a cross account trust and assume role using sts.
您需要做的是创建跨帐户信任并使用sts承担角色。
Create a role in the account with the kinesis stream, and set it to trust your lambda role. 使用运动学流在帐户中创建一个角色,并将其设置为信任您的lambda角色。
Give that role a policy that allows it to put to the kinesis stream. 为该角色提供一个策略,使其可以进入运动学流。
In your lambda code use sts to create a session in the account with the kinesis stream and put your record. 在您的lambda代码中,使用sts在帐户中使用kinesis流创建会话并放置记录。
Note your lambda will need a policy that allows it to sts into the second account's role. 请注意,您的lambda需要一个允许其进入第二个帐户角色的策略。
It is described a bit more clearly here Providing Access to Accounts you Own 这里提供了对您拥有的帐户的访问权限,对其进行了更清晰的描述
First you need to configure the Kinesis instance: 首先,您需要配置Kinesis实例:
(I chose Javascript for the example) (我选择Javascript作为示例)
var kinesis = new AWS.Kinesis({
accessKeyId: 'XXX',
secretAccessKey: 'YYY',
region: 'eu-west-1',
apiVersion: '2013-12-02'
});
For more informations take a look Constructing a Kinesis object 有关更多信息,请看构建Kinesis对象
To write/put a record use the following 要写/写记录,请使用以下命令
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
});
For more informations take a look Calling the putRecord operation 有关更多信息,请看一下调用putRecord操作
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.