Kinesis shard iterator types

You can specify one of the following shard iterator type values while retrieving the shard iterator value:

  • AT_SEQUENCE_NUMBER: Use this to read from the position specified by the sequence number, as follows:
aws kinesis get-shard-iterator 
--shard-id shardId-000000000000
--shard-iterator-type AT_SEQUENCE_NUMBER
--starting-sequence-number 49591022060730660638274567187983948851027405480717713410
--stream-name my-first-kinesis-stream
--profile admin

I have specified the sequence number of record 1. Here, the get-records command will return both records 1 and 2.

  • AFTER_SEQUENCE_NUMBERUse this to read after the position specified by the sequence number, as follows:
aws kinesis get-shard-iterator 
--shard-id shardId-000000000000
--shard-iterator-type AFTER_SEQUENCE_NUMBER
--starting-sequence-number 49591022060730660638274567187983948851027405480717713410
--stream-name my-first-kinesis-stream
--profile admin

I have again specified the sequence number of record 1, however, here the get-records command will return only record 2.

  • AT_TIMESTAMP: Use this to read from the specified timestamp, as follows:
aws kinesis get-shard-iterator 
--shard-id shardId-000000000000
--shard-iterator-type AT_TIMESTAMP
--timestamp 1544692680.484
--stream-name my-first-kinesis-stream
--profile admin

Provided the timestamp matches the first record, the get-records command will return both the records.

  • TRIM_HORIZON: Use this to return records from the oldest record after the last commit. We already looked at how to use this in this recipe.
  • LATEST: Use this to return the latest records that were added after the shard iterator was generated.

Let's look at how to use these types:

  1. We will first get the shard iterator that specifies the shard iterator type as LATEST:
aws kinesis get-shard-iterator 
--shard-id shardId-000000000000
--shard-iterator-type LATEST
--stream-name my-first-kinesis-stream
--profile admin
  1. Note down the iterator value and add a new record, as shown in the following code:
aws kinesis put-record 
--stream-name my-first-kinesis-stream
--partition-key 12345
--data sampledata03
--profile admin
  1. Invoke the aws kinesis get-records command, passing the shard iterator received in step 1:
aws kinesis get-records 
--shard-iterator <shard-iterator-value>
--profile admin

This will return only the latest record that was added after the shard iterator was created, which is sampledata03 (but encoded as before).

For more details, refer to the get-shard-iterator documentation reference link provided in the See also section.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
3.133.122.127