I am using the aws-sdk(version 2.1.8) to get records out from Kinesis. This is within a node Lambda function. Trying to use ShardIteratorType: AT_TIMESTAMP. I supply a Timestamp in the params object
const AWS = require("aws-sdk");
const kinesis = new AWS.Kinesis({ region: 'us-east-1' });
var params = {
ShardId: shard.ShardId, /* required */
ShardIteratorType: 'AT_TIMESTAMP', /* required */
StreamName: process.env.STREAM_NAME, /* required */
Timestamp: new Date(2017, 11, 08, 14, 32, 51)
};
kinesis.getShardIterator(params, function (err, data) {
if (err) {
return defer.reject(err);
}
defer.resolve(data);
});
But I get this error: Unexpected key 'Timestamp' found in params. Checked google, SO, and aws forums, to no avail. I am following the documentation from AWS: http://docs.aws.amazon.com/AWSJavaScriptSDK/latest/AWS/Kinesis.html#getShardIterator-property
Here are the logs from the Lambda function where I use getShardIterator
2017-11-08T15:53:13.551Z ec3ef291-c49c-11e7-ad35-473206669891 SHARD
ITERATOR TYPE: AT_TIMESTAMP
2017-11-08T15:53:13.551Z ec3ef291-c49c-11e7-ad35-473206669891
TIMESTAMP: 2017-12-08T14:32:51.000Z
ShardIteratorTypes LATEST and TRIM_HORIZON work fine. It is only when I try to use AT_TIMESTAMP that the issue occurs.
I found what was going on. The aws-sdk is taking the Timestamp value and multiplying it by 1000. This is insane - nowhere is this mentioned in the docs, where it simply states
The timestamp of the data record from which to start reading. Used with shard iterator type AT_TIMESTAMP. A timestamp is the Unix epoch date with precision in milliseconds
Therefore, using this
Timestamp: 1510673368611
will fail, even though it is a valid timestamp in milliseconds. You have to divide by 1000
Timestamp: 1510673368.611
This was pretty infuriating to discover. Just validate the value I send, don't alter it and then validate the result. Or, you know, MENTION THAT THIS HAPPENS IN THE DOCS.