1
votes

I have an AWS lambda that's hooked up to (triggered by) an AWS Kinesis Stream. When I fire events into Kinesis, my lambda gets called. Here's some example code that pushes events into Kinesis (this part works):

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();
});

When I successfully put a record, I get a response like this:

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

How can I use the SequenceNumber to look up the RequestId of the lambda being triggered?

1

1 Answers

1
votes

In your lambda handler, SequenceNumber is an element of event, and the RequestId is in context.aws_request_id

You can try with the lambda kinesis-process-record (from aws blueprint) to print the event received from kinesis and the context. It will have the form :

"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"
  }
]

So you find your sequenceNumber. It's the same for your RequestId in context.aws_request_id.

So depending on your need, you can log the 2 values in your lambda log, to know which RequestId has being triggered by which SequenceNumber