如何确定我的Kinesis事件触发了哪个特定的Lambda请求?

时间:2017-02-14 04:19:40

标签: node.js amazon-web-services aws-lambda amazon-kinesis

我有一个AWS lambda,它与AWS Kinesis Stream连接(由触发)。当我向Kinesis发射事件时,我的lambda被召唤。下面是一些将事件推送到Kinesis的示例代码(这部分有效):

var kinesis = new AWS.Kinesis({
  region: 'us-east-1'
});

var params = {
  Data: new Buffer(JSON.stringify(data)),
  StreamName: 'myStreamName',
  PartitionKey: uuid.v1()
};

kinesis.putRecord(params, function(err, data) {
  done();
});

当我成功录制唱片时,我得到这样的回复:

{ ShardId: 'shardId-000000000000', SequenceNumber: '49570419697469019326213778569044054238145932258132885506' }

如何使用SequenceNumber查找被触发的lambda的RequestId?

1 个答案:

答案 0 :(得分:1)

在lambda处理程序中,SequenceNumberevent的元素,而RequestId位于context.aws_request_id

您可以尝试使用lambda kinesis-process-record(来自aws blueprint)来打印从kinesis和event收到的context。 它将具有以下形式:

"Records": [
  {
    "eventVersion": "1.0",
    "eventID": "shardId-000000000003:435694251339676724843833861912342195614145114762801",
    "kinesis": {
      "approximateArrivalTimestamp": 1487001596.082,
      "partitionKey": "xx",
      "data": "xxx",
      "kinesisSchemaVersion": "1.0",
      "sequenceNumber": "435694251339676724843833861912342195614145114762801"
    },
    "invokeIdentityArn": "xxx",
    "eventName": "aws:kinesis:record",
    "eventSourceARN": "xxx",
    "eventSource": "aws:kinesis",
    "awsRegion": "xxx"
  }
]

所以你找到了sequenceNumberRequestIdcontext.aws_request_id的内容相同。

因此,根据您的需要,您可以在lambda日志中记录2个值,以了解哪个RequestId由哪个SequenceNumber触发