How to Send and Read Data with Kinesis on AWS Emulator
I created a Kinesis Data Streams stream, sent data with the AWS CLI put-record command, and read it back with get-shard-iterator and get-records, all on the AWS Emulator locally without an AWS account. These steps are for checking a streaming workflow that sends events such as page clicks or access logs in order, in a local environment or in CI. I also cover --cli-binary-format, which is easy to forget when sending with AWS CLI v2, and the types of shard iterator that decide where reading starts. I include the commands and their output as they ran; long output is partly omitted.
The test environment was Ubuntu 24.04 (x86_64), AWS Emulator 1.0.556 (released November 21, 2026, Debian package), AWS CLI 2.42.1, and jq 1.7. I did not use an AWS account or credentials. I did not verify how real Kinesis Data Streams behaves for limits on the number and volume of reads and writes and ProvisionedThroughputExceededException, partial failures in put-records, the delay before data becomes readable, or pricing; where this article mentions them, the source is the official documentation. I did not test on-demand mode, shard splitting and merging, enhanced fan-out, AT_TIMESTAMP, or reading and writing from an SDK or the KCL (Kinesis Client Library). The emulator does not evaluate IAM policies the same way AWS does.
- 1. Start the emulator and point the AWS CLI at it
- 2. Create a stream with two shards
- 3. Use –cli-binary-format when sending with put-record
- 4. Send several records at once with put-records
- 5. Get a shard iterator and read each shard
- 6. Continue reading with NextShardIterator
- 7. Change where reading starts
- 8. Common errors
- 9. Delete the stream
Start the emulator and point the AWS CLI at it
I installed AWS Emulator from a Debian package after verifying its signature, following the official Linux installation guide. I started it in a separate terminal (or in the background) with aws-emulator -t off. -t off disables sending usage data (telemetry).
In the terminal where I run the AWS CLI, I set the environment variables from the official instructions for pointing SDKs and the CLI at the emulator. The last line, AWS_PAGER="", is something I added so output is not stopped by a pager.
export AWS_ENDPOINT_URL=https://127.0.0.1:9297
export AWS_SHARED_CREDENTIALS_FILE=~/.aws/emulator/9297/emulator_credentials
export AWS_CONFIG_FILE=~/.aws/emulator/9297/config
export AWS_CA_BUNDLE=~/.aws/emulator/9297/ca.pem
export AWS_EC2_METADATA_DISABLED=true
export AWS_DISABLE_HOST_PREFIX_INJECTION=true
export AWS_REGION=us-east-1
export AWS_DEFAULT_REGION=us-east-1
unset AWS_ACCESS_KEY_ID AWS_SECRET_ACCESS_KEY AWS_SESSION_TOKEN AWS_PROFILE
export AWS_PAGER=""
Create a stream with two shards
A stream has one or more shards, which keep records in the order they arrive. I used two shards so I could also see which shard each record goes to.
$ aws kinesis create-stream --stream-name example-clicks --shard-count 2
$ aws kinesis wait stream-exists --stream-name example-clicks
$ aws kinesis describe-stream-summary --stream-name example-clicks --query "StreamDescriptionSummary.{Status:StreamStatus,Mode:StreamModeDetails.StreamMode,OpenShardCount:OpenShardCount,RetentionPeriodHours:RetentionPeriodHours}"
{
"Status": "ACTIVE",
"Mode": "PROVISIONED",
"OpenShardCount": 2,
"RetentionPeriodHours": 24
}
Mode in the output is PROVISIONED. As the official CreateStream reference describes, in PROVISIONED mode, where you choose the number of shards yourself, you specify --shard-count. The retention period (RetentionPeriodHours) was the default of 24 hours, per the official PutRecord reference. Running list-shards shows the IDs of the two shards and the hash key range each one covers.
$ aws kinesis list-shards --stream-name example-clicks
{
"Shards": [
{
"ShardId": "shardId-000000000000",
"HashKeyRange": {
"StartingHashKey": "0",
"EndingHashKey": "170141183460469231731687303715884105727"
},
...
},
{
"ShardId": "shardId-000000000001",
"HashKeyRange": {
"StartingHashKey": "170141183460469231731687303715884105728",
"EndingHashKey": "340282366920938463463374607431768211455"
},
...
}
]
}
The 128-bit hash key space is split exactly in half between the two shards (... stands for the omitted SequenceNumberRange).
Use –cli-binary-format when sending with put-record
To send one record at a time, use put-record. --partition-key is a string that decides which shard the record goes to. Here I used a per-user ID.
$ aws kinesis put-record --stream-name example-clicks --partition-key user-1 --data '{"page":"/top"}' --cli-binary-format raw-in-base64-out
{
"ShardId": "shardId-000000000001",
"SequenceNumber": "491795282418592000001000000000000"
}
$ aws kinesis put-record --stream-name example-clicks --partition-key user-2 --data '{"page":"/top"}' --cli-binary-format raw-in-base64-out
{
"ShardId": "shardId-000000000000",
"SequenceNumber": "491795282418592000000000000000000"
}
The response contains the ID of the shard the record went into and the sequence number assigned to it.
--cli-binary-format raw-in-base64-out tells the CLI to send the string given to --data as-is. AWS CLI v2 defaults to treating binary arguments as base64-encoded strings, so without this option the --data string is read as base64. I tried sending to a different stream (example-raw) without the option.
$ aws kinesis put-record --stream-name example-raw --partition-key user-9 --data '{"page":"/oops"}'
aws: [ERROR]: Invalid base64: "{"page":"/oops"}"
$ aws kinesis put-record --stream-name example-raw --partition-key user-9 --data '{"page":"/top"}'
{
"ShardId": "shardId-000000000000",
"SequenceNumber": "491795282423293000000000000000000"
}
The first attempt stopped with an error, but the second succeeded. When I read back the second record, Data was page/top. That is the sent string with {, ", :, and } removed.
$ aws kinesis get-records --shard-iterator $IT --query 'Records[].{Key:PartitionKey,Data:Data}'
[
{
"Key": "user-9",
"Data": "page/top"
}
]
$ printf %s 'page/top' | base64 -d | od -An -tx1
a5 a8 1e fe da 29
The Data returned by the read is a base64 string. Decoding it gave six bytes that are not JSON.
When passing a string as-is to put-record or put-records with AWS CLI v2, add --cli-binary-format raw-in-base64-out. If you forget it, some strings are still accepted without an error, and the stream then holds byte sequences you did not intend to send.
Send several records at once with put-records
To send multiple records in one call, use put-records. Putting the arguments in a JSON file makes it easier to write the quotes inside Data.
$ cat records.json
[
{"Data": "{\"page\":\"/a\"}", "PartitionKey": "user-1"},
{"Data": "{\"page\":\"/b\"}", "PartitionKey": "user-2"},
{"Data": "{\"page\":\"/c\"}", "PartitionKey": "user-3"}
]
$ aws kinesis put-records --stream-name example-clicks --records file://records.json --cli-binary-format raw-in-base64-out
{
"FailedRecordCount": 0,
"Records": [
{
"SequenceNumber": "491795282418592000001000000000001",
"ShardId": "shardId-000000000001"
},
{
"SequenceNumber": "491795282418592000000000000000001",
"ShardId": "shardId-000000000000"
},
{
"SequenceNumber": "491795282418592000000000000000002",
"ShardId": "shardId-000000000000"
}
]
}
Each entry in Records corresponds to a record in the order sent. FailedRecordCount is 0, so all three were stored. According to the official PutRecords reference, one call accepts up to 500 records, and on real AWS, some records in a call can fail while others succeed. Each failed record is returned with an ErrorCode and ErrorMessage, and the rest are still processed. So when FailedRecordCount is not 0, resend only the entries that have an ErrorCode.
user-1's two records both went to shardId-000000000001, and user-2 and user-3 went to shardId-000000000000. The official PutRecord reference says the partition key is hashed with MD5 into a 128-bit integer, and the record goes to the shard whose range contains it. I ran the same calculation in Python, and the results matched.
$ python3 -c 'import hashlib; [print(k, int(hashlib.md5(k.encode()).hexdigest(), 16) >= 2**127 and "shardId-000000000001" or "shardId-000000000000") for k in ("user-1", "user-2", "user-3")]'
user-1 shardId-000000000001
user-2 shardId-000000000000
user-3 shardId-000000000000
Records with the same partition key go to the same shard. However, according to the official PutRecords reference, put-records does not guarantee that records are stored in the order they were sent. If you need records in the order you wrote them, send them to the same shard with put-record. (The official PutRecord reference says that to strictly preserve ordering, you use SequenceNumberForOrdering.)
Get a shard iterator and read each shard
To read, first call get-shard-iterator to get a shard iterator, which specifies which shard to read and from where. Pass it to get-records to get the data. Reading is done per shard, so with two shards you read twice.
--shard-iterator-type TRIM_HORIZON means read from the oldest data still retained in the shard.
$ IT=$(aws kinesis get-shard-iterator --stream-name example-clicks --shard-id shardId-000000000000 --shard-iterator-type TRIM_HORIZON --query ShardIterator --output text)
$ aws kinesis get-records --shard-iterator $IT --query 'Records[].{Seq:SequenceNumber,Key:PartitionKey,Data:Data}'
[
{
"Seq": "491795282418592000000000000000000",
"Key": "user-2",
"Data": "eyJwYWdlIjoiL3RvcCJ9"
},
{
"Seq": "491795282418592000000000000000001",
"Key": "user-2",
"Data": "eyJwYWdlIjoiL2IifQ=="
},
{
"Seq": "491795282418592000000000000000002",
"Key": "user-3",
"Data": "eyJwYWdlIjoiL2MifQ=="
}
]
Shard iterators are long strings, so in this article I store one in $IT. Data comes back as a base64 string. Decoding it with jq's @base64d gives back the JSON that was sent. I read the other shard the same way.
$ IT=$(aws kinesis get-shard-iterator --stream-name example-clicks --shard-id shardId-000000000001 --shard-iterator-type TRIM_HORIZON --query ShardIterator --output text)
$ aws kinesis get-records --shard-iterator $IT --output json | jq -r '.Records[] | "\(.PartitionKey) \(.Data | @base64d)"'
user-1 {"page":"/top"}
user-1 {"page":"/a"}
In both shards, records come back in ascending sequence number order, which is the order they were sent. As the official PutRecord reference states, sequence numbers increase within each shard, but they do not represent an ordering across the whole stream.
Continue reading with NextShardIterator
The response from get-records includes NextShardIterator, which marks where to read next. I read two records with --limit 2, then continued with NextShardIterator.
$ aws kinesis get-records --shard-iterator $IT --limit 2 --query '{Seq:Records[].SequenceNumber,Next:NextShardIterator,MillisBehindLatest:MillisBehindLatest}'
{
"Seq": [
"491795282418592000000000000000000",
"491795282418592000000000000000001"
],
"Next": "7368617264497465726174…(以下略)",
"MillisBehindLatest": 7408
}
$ aws kinesis get-records --shard-iterator $NEXT --query '{Seq:Records[].SequenceNumber,MillisBehindLatest:MillisBehindLatest}'
{
"Seq": [
"491795282418592000000000000000002"
],
"MillisBehindLatest": 0
}
Here $IT is a TRIM_HORIZON iterator for shardId-000000000000, fetched again. $NEXT is the NextShardIterator returned by a call identical to the first one, and $NEXT2, used later, is the NextShardIterator returned by a call identical to the second one. The second call returned only the one remaining record. According to the official GetRecords reference, MillisBehindLatest is the number of milliseconds by which the read position is behind the latest record in the shard; 0 means the reader has caught up.
When I read again after catching up, Records was empty. After I sent a record to the same shard, reading with the same iterator returned only the one newly arrived record.
$ aws kinesis get-records --shard-iterator $NEXT2 --query '{Records:Records,MillisBehindLatest:MillisBehindLatest}'
{
"Records": [],
"MillisBehindLatest": 0
}
$ aws kinesis put-record --stream-name example-clicks --partition-key user-2 --data '{"page":"/d"}' --cli-binary-format raw-in-base64-out
{
"ShardId": "shardId-000000000000",
"SequenceNumber": "491795282418592000000000000000003"
}
$ aws kinesis get-records --shard-iterator $NEXT2 --output json | jq -r '.Records[] | "\(.SequenceNumber) \(.PartitionKey) \(.Data | @base64d)"'
491795282418592000000000000000003 user-2 {"page":"/d"}
A program that keeps reading calls get-records, then passes the NextShardIterator to the next call, repeating this loop. On real AWS, the GetRecords reference states that get-records is limited to 5 calls per second per shard, and recommends waiting one second between calls.
Change where reading starts
The type of shard iterator determines where reading starts. The contents of shardId-000000000000 at this point, and where each iterator type starts reading, are shown below.

When you want to stop processing partway and resume later, save the sequence number of the last record you processed, then re-read with AT_SEQUENCE_NUMBER or AFTER_SEQUENCE_NUMBER. I passed the sequence number of the second record (ending in 0001) and compared the results.
$ IT=$(aws kinesis get-shard-iterator --stream-name example-clicks --shard-id shardId-000000000000 --shard-iterator-type AT_SEQUENCE_NUMBER --starting-sequence-number 491795282418592000000000000000001 --query ShardIterator --output text)
$ aws kinesis get-records --shard-iterator $IT --output json | jq -r '.Records[] | "\(.SequenceNumber) \(.PartitionKey) \(.Data | @base64d)"'
491795282418592000000000000000001 user-2 {"page":"/b"}
491795282418592000000000000000002 user-3 {"page":"/c"}
491795282418592000000000000000003 user-2 {"page":"/d"}
$ IT=$(aws kinesis get-shard-iterator --stream-name example-clicks --shard-id shardId-000000000000 --shard-iterator-type AFTER_SEQUENCE_NUMBER --starting-sequence-number 491795282418592000000000000000001 --query ShardIterator --output text)
$ aws kinesis get-records --shard-iterator $IT --output json | jq -r '.Records[] | "\(.SequenceNumber) \(.PartitionKey) \(.Data | @base64d)"'
491795282418592000000000000000002 user-3 {"page":"/c"}
491795282418592000000000000000003 user-2 {"page":"/d"}
AT_SEQUENCE_NUMBER returned records starting from the one with the given number, and AFTER_SEQUENCE_NUMBER returned records starting from the one after it. If you save the sequence numbers of records you have already processed, use AFTER_SEQUENCE_NUMBER so the same record is not processed twice.
LATEST means skip the records already in the shard when you get the iterator, and read from records that arrive afterward. I tried this on shardId-000000000001.
$ IT=$(aws kinesis get-shard-iterator --stream-name example-clicks --shard-id shardId-000000000001 --shard-iterator-type LATEST --query ShardIterator --output text)
$ aws kinesis get-records --shard-iterator $IT --query 'length(Records)'
0
$ aws kinesis put-record --stream-name example-clicks --partition-key user-1 --data '{"page":"/e"}' --cli-binary-format raw-in-base64-out
{
"ShardId": "shardId-000000000001",
"SequenceNumber": "491795282418592000001000000000002"
}
$ aws kinesis get-records --shard-iterator $IT --output json | jq -r '.Records[] | "\(.SequenceNumber) \(.PartitionKey) \(.Data | @base64d)"'
491795282418592000001000000000002 user-1 {"page":"/e"}
This shard already had two records, but the first get-records returned zero. Only /e, which I sent after getting the iterator, was returned.
Common errors
Specifying a shard ID that does not exist gave ResourceNotFoundException. (The account ID in the output is replaced with a placeholder.)
$ aws kinesis get-shard-iterator --stream-name example-clicks --shard-id shardId-000000000009 --shard-iterator-type TRIM_HORIZON
aws: [ERROR]: An error occurred (ResourceNotFoundException) when calling the GetShardIterator operation: Could not find shard shardId-000000000009 in stream example-clicks under account <12桁のアカウントID>.
Sending without --partition-key gave InvalidArgumentException.
$ aws kinesis put-record --stream-name example-clicks --data '{"page":"/x"}' --cli-binary-format raw-in-base64-out
aws: [ERROR]: An error occurred (InvalidArgumentException) when calling the PutRecord operation: PartitionKey is required for a stream that uses the USER_PARTITION_KEY record distribution strategy
Shard iterators also expire. The official GetShardIterator reference says they expire 5 minutes after they are returned. On the emulator, when I waited 5 minutes and 10 seconds after getting an iterator before using it, I got ExpiredIteratorException.
$ aws kinesis get-records --shard-iterator $IT --query 'length(Records)'
aws: [ERROR]: An error occurred (ExpiredIteratorException) when calling the GetRecords operation: Iterator expired. The iterator was created at time Sat Nov 21 17:34:10 UTC 2026 while right now it is Sat Nov 21 17:39:20 UTC 2026 which is further in the future than the tolerated delay of 300000 milliseconds.
When you see this error, get a new iterator. If you pass the sequence number you saved to AFTER_SEQUENCE_NUMBER, you can read from the record after it, as I tested earlier.
Delete the stream
When you are done testing, delete the stream.
$ aws kinesis delete-stream --stream-name example-clicks
$ aws kinesis wait stream-not-exists --stream-name example-clicks
$ aws kinesis list-streams
{
"StreamNames": [],
"StreamSummaries": []
}
The emulator keeps everything it creates in memory, and it is lost when the emulator stops. If you restart it for each test run, you start from an empty set of streams.





