Step 2 - Adding and retrieving data

You can add data to a KDS from the CLI using the aws kinesis put-record command, as follows:

aws kinesis put-record 
--stream-name my-first-kinesis-stream
--partition-key 12345
--data sampledata01
--profile admin

This will return the shard ID and the sequence number of the record, as shown in the following screenshot:

Similarly, you can add one more data item with a payload of sampledata02.

Retrieving data from a KDS is a two-step process:

  1. Get the shard iterator:
aws kinesis get-shard-iterator 
--shard-id shardId-000000000000
--shard-iterator-type TRIM_HORIZON
--stream-name my-first-kinesis-stream
--profile admin

This will return the following response:

  1. Invoke the aws kinesis get-records command to pass the shard iterator, as shown in the following code:
aws kinesis get-records 
--shard-iterator <shard-iterator-value>
--profile admin

Use the shard iterator value from the previous step. This should give the following response:

The TRIM_HORIZON option return records from the oldest record. If you try to use the get-records command with the next shard iterator returned by this command, you will not get any records as it has retrieved all of the records already.

The data in the response is Base64 encoded, and so needs to be decoded. You can do a quick Google search to find an online decoder, or if you are using a Mac or a similar OS, you can also use the following command to decode the Base64-encoded string:

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

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