Kinesis Data Streams
Stream events locally with real Kinesis APIs. Create streams, put records, consume with shard iterators, manage shards and tags. Pure Python, no external processes, no Docker containers needed.
ACTIVE, puts three records via
put-record (each tagged with a partition key
derived from the event's user, sent as raw bytes the way AWS CLI v1 expects), reads the records back by getting a
TRIM_HORIZON shard iterator and calling
get-records, scales the stream to two shards,
tags it, then runs a small Python script (src/kinesis_demo.py)
that produces three more payloads with boto3
and asserts every payload round-trips byte-identical via the consumer.
No special LocalEmu flags required: Kinesis runs in-process, no Docker container.
Source: 12-kinesis-demo/ in the examples repo.
Real Streams
Create streams, put records, consume with shard iterators. Full Kinesis Data Streams API.
Shard Management
Split and merge shards, update shard count, track sequence numbers and hash key ranges.
Pure Python
No Node.js, no external process, no Docker. Kinesis runs directly inside LocalEmu's Python runtime.
Step-by-Step Walkthrough
Step 1: Start LocalEmu
$ localemu start
Starting LocalEmu...
LocalEmu version: 1.4.0
Ready. No special environment variables needed. Kinesis is a pure Python service - it starts automatically with LocalEmu.
Step 2: Create a Kinesis stream
$ aws --endpoint-url=http://localhost:4566 kinesis create-stream --stream-name my-stream --shard-count 1 Creates a stream with 1 shard. The command returns immediately with no output (HTTP 200).
Step 3: Describe the stream
$ aws --endpoint-url=http://localhost:4566 kinesis describe-stream --stream-name my-stream
{
"StreamDescription": {
"Shards": [
{
"ShardId": "shardId-000000000000",
"HashKeyRange": {
"StartingHashKey": "0",
"EndingHashKey": "340282366920938463463374607431768211456"
},
"SequenceNumberRange": {
"StartingSequenceNumber": "0"
}
}
],
"StreamARN": "arn:aws:kinesis:us-east-1:000000000000:stream/my-stream",
"StreamName": "my-stream",
"StreamStatus": "ACTIVE",
"RetentionPeriodHours": 24,
"EnhancedMonitoring": [
{
"ShardLevelMetrics": []
}
],
"EncryptionType": "NONE",
"KeyId": null,
"StreamCreationTimestamp": 1775864300.265016
}
} Stream is ACTIVE immediately. One shard with a full hash key range, 24-hour retention, no encryption. Ready for records.
Step 4: Put 3 records (login, purchase, logout)
$ aws --endpoint-url=http://localhost:4566 kinesis put-record --stream-name my-stream \
--partition-key "user-tarek" \
--data '{"event":"login","user":"tarek"}'
{
"ShardId": "shardId-000000000000",
"SequenceNumber": "49665545667876736539633793224463652467319242024123889666"
}
$ aws --endpoint-url=http://localhost:4566 kinesis put-record --stream-name my-stream \
--partition-key "user-alice" \
--data '{"event":"purchase","user":"alice","amount":99.99}'
{
"ShardId": "shardId-000000000000",
"SequenceNumber": "49665545667876736539633793224464861393139779656455388098"
}
$ aws --endpoint-url=http://localhost:4566 kinesis put-record --stream-name my-stream \
--partition-key "user-tarek" \
--data '{"event":"logout","user":"tarek"}'
{
"ShardId": "shardId-000000000000",
"SequenceNumber": "49665545667876736539633793224466070318960252847677138034"
} Each record gets a monotonically increasing sequence number. AWS CLI v1 sends --data as raw bytes directly, no manual base64 encoding needed on the way in; Kinesis still returns the stored bytes base64-encoded when you read them back (see Step 5). Partition keys (user-tarek, user-alice) hash into the shard key range, so all records for the same key land on the same shard.
Step 5: Get shard iterator and read all records
$ SHARD_ID=$(aws --endpoint-url=http://localhost:4566 kinesis describe-stream --stream-name my-stream \
--query 'StreamDescription.Shards[0].ShardId' --output text)
$ ITER=$(aws --endpoint-url=http://localhost:4566 kinesis get-shard-iterator --stream-name my-stream \
--shard-id "$SHARD_ID" --shard-iterator-type TRIM_HORIZON \
--query 'ShardIterator' --output text)
$ aws --endpoint-url=http://localhost:4566 kinesis get-records --shard-iterator "$ITER" --limit 100 | python3 -c "
import base64, json, sys
resp = json.load(sys.stdin)
print(f'MillisBehindLatest: {resp[\"MillisBehindLatest\"]}')
for r in resp['Records']:
data = json.loads(base64.b64decode(r['Data']))
print(f' seq={r[\"SequenceNumber\"]} pk={r[\"PartitionKey\"]} -> {data}')
"
MillisBehindLatest: 0
seq=49665545667876736539633793224463652467319242024123889666 pk=user-tarek -> {'event': 'login', 'user': 'tarek'}
seq=49665545667876736539633793224464861393139779656455388098 pk=user-alice -> {'event': 'purchase', 'user': 'alice', 'amount': 99.99}
seq=49665545667876736539633793224466070318960252847677138034 pk=user-tarek -> {'event': 'logout', 'user': 'tarek'} TRIM_HORIZON reads from the beginning of the shard. get-records returns each record's Data base64-encoded, so the pipe decodes it before printing; all 3 payloads come back byte-identical. MillisBehindLatest: 0 means the consumer is fully caught up.
Step 6: List streams
$ aws --endpoint-url=http://localhost:4566 kinesis list-streams --query 'StreamNames'
[
"my-stream"
] Confirms my-stream is the only stream currently provisioned.
Step 7: Scale up - update shard count from 1 to 2
$ aws --endpoint-url=http://localhost:4566 kinesis update-shard-count --stream-name my-stream \
--target-shard-count 2 --scaling-type UNIFORM_SCALING
{
"StreamName": "my-stream",
"CurrentShardCount": 1,
"TargetShardCount": 2
} UNIFORM_SCALING splits shards evenly. The response confirms the change from 1 to 2 shards.
Step 8: Tag the stream
$ aws --endpoint-url=http://localhost:4566 kinesis add-tags-to-stream --stream-name my-stream \
--tags env=dev,team=platform
$ aws --endpoint-url=http://localhost:4566 kinesis list-tags-for-stream --stream-name my-stream
{
"Tags": [
{
"Key": "env",
"Value": "dev"
},
{
"Key": "team",
"Value": "platform"
}
],
"HasMoreTags": false
} Tags work exactly like AWS. Use them for cost allocation, environment tracking, or team ownership.
Step 9: Delete the stream and verify
$ aws --endpoint-url=http://localhost:4566 kinesis delete-stream --stream-name my-stream
$ aws --endpoint-url=http://localhost:4566 kinesis list-streams
{
"StreamNames": [],
"StreamSummaries": []
}
(stream deleted - clean state) Stream deleted instantly. List streams confirms empty state. Clean teardown, every time.
Server Logs
LocalEmu logs every Kinesis API call with timestamps and HTTP status codes. Here is what the server side looks like during the walkthrough above.
2026-04-10T23:38:20.265 INFO --- [et.reactor-0] localemu.request.aws : AWS kinesis.CreateStream => 200
2026-04-10T23:39:11.400 INFO --- [et.reactor-0] localemu.request.aws : AWS kinesis.PutRecord => 200
2026-04-10T23:39:27.835 INFO --- [et.reactor-0] localemu.request.aws : AWS kinesis.PutRecord => 200
2026-04-10T23:39:40.685 INFO --- [et.reactor-0] localemu.request.aws : AWS kinesis.PutRecord => 200
2026-04-10T23:40:29.474 INFO --- [et.reactor-0] localemu.request.aws : AWS kinesis.GetRecords => 200 Python Integration (boto3)
A complete producer and consumer in one script, copied verbatim from the example repo (src/kinesis_demo.py). It hardcodes the standard AWS example access key/secret pair so it runs fully offline against LocalEmu; point it at real AWS Kinesis by swapping in real credentials and dropping the endpoint_url argument.
"""Kinesis producer + consumer in one script.
Creates a stream, writes 3 events, reads them back with a shard iterator,
asserts the payloads decode correctly, and deletes the stream.
"""
from __future__ import annotations
import json
import sys
import time
import boto3
def main() -> int:
kinesis = boto3.client(
"kinesis",
endpoint_url="http://localhost:4566",
region_name="us-east-1",
aws_access_key_id="AKIAIOSFODNN7EXAMPLE",
aws_secret_access_key="wJalrXUtnFEMI/K7MDENG/bPxRfiCYEXAMPLEKEY",
)
stream_name = "events"
# Fresh stream
try:
kinesis.delete_stream(StreamName=stream_name)
kinesis.get_waiter("stream_not_exists").wait(StreamName=stream_name)
except kinesis.exceptions.ResourceNotFoundException:
pass
kinesis.create_stream(StreamName=stream_name, ShardCount=1)
kinesis.get_waiter("stream_exists").wait(StreamName=stream_name)
print(f"→ stream '{stream_name}' is ACTIVE")
# Producer
events = [
{"event": "login", "user": "tarek"},
{"event": "purchase", "user": "alice", "amount": 99.99},
{"event": "logout", "user": "tarek"},
]
print("\n→ producer: writing 3 events")
for evt in events:
resp = kinesis.put_record(
StreamName=stream_name,
Data=json.dumps(evt).encode("utf-8"),
PartitionKey=f"user-{evt['user']}",
)
print(f" seq={resp['SequenceNumber']} shard={resp['ShardId']} payload={evt}")
# Consumer: read all records from TRIM_HORIZON
desc = kinesis.describe_stream(StreamName=stream_name)
shard_id = desc["StreamDescription"]["Shards"][0]["ShardId"]
iterator = kinesis.get_shard_iterator(
StreamName=stream_name,
ShardId=shard_id,
ShardIteratorType="TRIM_HORIZON",
)["ShardIterator"]
# Poll until we see all 3 records (shard read is eventually-consistent but fast)
seen: list[dict] = []
deadline = time.monotonic() + 10
while len(seen) < len(events) and time.monotonic() < deadline:
response = kinesis.get_records(ShardIterator=iterator, Limit=100)
for r in response["Records"]:
seen.append(
{
"seq": r["SequenceNumber"],
"partition_key": r["PartitionKey"],
"payload": json.loads(r["Data"]),
}
)
iterator = response["NextShardIterator"]
if len(seen) < len(events):
time.sleep(0.2)
print(f"\n→ consumer: read {len(seen)} records")
for rec in seen:
print(f" seq={rec['seq']} pk={rec['partition_key']} payload={rec['payload']}")
# Verify payloads round-tripped intact
assert len(seen) == len(events), f"expected {len(events)} records, got {len(seen)}"
for expected, got in zip(events, [r["payload"] for r in seen]):
assert got == expected, f"payload mismatch: {got} != {expected}"
print("\n→ all 3 payloads round-tripped intact")
kinesis.delete_stream(StreamName=stream_name)
print(f"→ stream '{stream_name}' deleted")
return 0
if __name__ == "__main__":
sys.exit(main()) How It Works
Pure Python - no Node.js, no external process
Kinesis runs directly in LocalEmu. Unlike OpenSearch or RDS (which spin up Docker containers), Kinesis is implemented entirely in Python via Moto. This means instant startup, zero resource overhead, and no Docker dependency. Just localemu start and you are ready to stream.
Known gap: Enhanced Fan-Out child-shard info
Enhanced Fan-Out is supported (SubscribeToShard). KCL re-sharding via the ChildShards field on each event is a known gap (TODO at services/kinesis/provider.py:252). Consumers that rely on child-shard info to follow splits/merges will not see them. Plain producer + consumer flows (the walkthrough above) are unaffected.