Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 10 additions & 2 deletions moto/kinesis/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -432,8 +432,16 @@ def put_record(

return sequence_number, shard.shard_id

def to_json(self, shard_limit: int | None = None) -> dict[str, Any]:
all_shards = list(self.shards.values())
def to_json(
self,
shard_limit: int | None = None,
exclusive_start_shard_id: str | None = None,
) -> dict[str, Any]:
all_shards = [
shard
for shard in self.shards.values()
if not exclusive_start_shard_id or shard.shard_id > exclusive_start_shard_id
]
requested_shards = all_shards[0 : shard_limit or len(all_shards)]
return {
"StreamDescription": {
Expand Down
7 changes: 6 additions & 1 deletion moto/kinesis/responses.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,13 @@ def describe_stream(self) -> ActionResult:
stream_name = self._get_param("StreamName")
stream_arn = self._get_param("StreamARN")
limit = self._get_param("Limit")
exclusive_start_shard_id = self._get_param("ExclusiveStartShardId")
stream = self.kinesis_backend.describe_stream(stream_arn, stream_name)
return ActionResult(stream.to_json(shard_limit=limit))
return ActionResult(
stream.to_json(
shard_limit=limit, exclusive_start_shard_id=exclusive_start_shard_id
)
)

def describe_stream_summary(self) -> ActionResult:
stream_arn = self._get_param("StreamARN")
Expand Down
33 changes: 33 additions & 0 deletions tests/test_kinesis/test_kinesis_boto3.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,39 @@ def test_describe_stream_limit_parameter():
assert with_filter["HasMoreShards"] is False


@mock_aws
def test_describe_stream_exclusive_start_shard_id():
client = boto3.client("kinesis", region_name="us-west-2")
stream_name = "my_stream"

client.create_stream(StreamName=stream_name, ShardCount=5)

desc = client.describe_stream(
StreamName=stream_name, Limit=2, ExclusiveStartShardId="shardId-000000000001"
)["StreamDescription"]
assert [s["ShardId"] for s in desc["Shards"]] == [
"shardId-000000000002",
"shardId-000000000003",
]
assert desc["HasMoreShards"] is True

desc = client.describe_stream(
StreamName=stream_name, Limit=2, ExclusiveStartShardId="shardId-000000000003"
)["StreamDescription"]
assert [s["ShardId"] for s in desc["Shards"]] == ["shardId-000000000004"]
assert desc["HasMoreShards"] is False

pages = client.get_paginator("describe_stream").paginate(
StreamName=stream_name, PaginationConfig={"PageSize": 2}
)
shard_ids = [
shard["ShardId"]
for page in pages
for shard in page["StreamDescription"]["Shards"]
]
assert shard_ids == [f"shardId-00000000000{i}" for i in range(5)]


@mock_aws
def test_list_shards():
conn = boto3.client("kinesis", region_name="us-west-2")
Expand Down