- Navigation GuideYou are on a Command (operation) page with structural examples. Use the navigation breadcrumb if you would like to return to the Client landing page.
ListShardsCommand
Lists the shards in a stream and provides information about each shard. This operation has a limit of 1000 transactions per second per data stream.
When invoking this API, you must use either the StreamARN
or the StreamName
parameter, or both. It is recommended that you use the StreamARN
input parameter when you invoke this API.
This action does not list expired shards. For information about expired shards, see Data Routing, Data Persistence, and Shard State after a Reshard .
This API is a new operation that is used by the Amazon Kinesis Client Library (KCL). If you have a fine-grained IAM policy that only allows specific operations, you must update your policy to allow calls to this API. For more information, see Controlling Access to Amazon Kinesis Data Streams Resources Using IAM .
Example Syntax
Use a bare-bones client and the command you need to make an API call.
import { KinesisClient, ListShardsCommand } from "@aws-sdk/client-kinesis"; // ES Modules import
// const { KinesisClient, ListShardsCommand } = require("@aws-sdk/client-kinesis"); // CommonJS import
const client = new KinesisClient(config);
const input = { // ListShardsInput
StreamName: "STRING_VALUE",
NextToken: "STRING_VALUE",
ExclusiveStartShardId: "STRING_VALUE",
MaxResults: Number("int"),
StreamCreationTimestamp: new Date("TIMESTAMP"),
ShardFilter: { // ShardFilter
Type: "AFTER_SHARD_ID" || "AT_TRIM_HORIZON" || "FROM_TRIM_HORIZON" || "AT_LATEST" || "AT_TIMESTAMP" || "FROM_TIMESTAMP", // required
ShardId: "STRING_VALUE",
Timestamp: new Date("TIMESTAMP"),
},
StreamARN: "STRING_VALUE",
};
const command = new ListShardsCommand(input);
const response = await client.send(command);
// { // ListShardsOutput
// Shards: [ // ShardList
// { // Shard
// ShardId: "STRING_VALUE", // required
// ParentShardId: "STRING_VALUE",
// AdjacentParentShardId: "STRING_VALUE",
// HashKeyRange: { // HashKeyRange
// StartingHashKey: "STRING_VALUE", // required
// EndingHashKey: "STRING_VALUE", // required
// },
// SequenceNumberRange: { // SequenceNumberRange
// StartingSequenceNumber: "STRING_VALUE", // required
// EndingSequenceNumber: "STRING_VALUE",
// },
// },
// ],
// NextToken: "STRING_VALUE",
// };
ListShardsCommand Input
Parameter | Type | Description |
---|
Parameter | Type | Description |
---|---|---|
ExclusiveStartShardId | string | undefined | Specify this parameter to indicate that you want to list the shards starting with the shard whose ID immediately follows If you don't specify this parameter, the default behavior is for You cannot specify this parameter if you specify |
MaxResults | number | undefined | The maximum number of shards to return in a single call to When the number of shards to be listed is greater than the value of |
NextToken | string | undefined | When the number of shards in the data stream is greater than the default value for the Don't specify You can optionally specify a value for the Tokens expire after 300 seconds. When you obtain a value for |
ShardFilter | ShardFilter | undefined | Enables you to filter out the response of the If you use the If you specify the If you specify the |
StreamARN | string | undefined | The ARN of the stream. |
StreamCreationTimestamp | Date | undefined | Specify this input parameter to distinguish data streams that have the same name. For example, if you create a data stream and then delete it, and you later create another data stream with the same name, you can use this input parameter to specify which of the two streams you want to list the shards for. You cannot specify this parameter if you specify the |
StreamName | string | undefined | The name of the data stream whose shards you want to list. You cannot specify this parameter if you specify the |
ListShardsCommand Output
Parameter | Type | Description |
---|
Parameter | Type | Description |
---|---|---|
$metadata Required | ResponseMetadata | Metadata pertaining to this request. |
NextToken | string | undefined | When the number of shards in the data stream is greater than the default value for the Tokens expire after 300 seconds. When you obtain a value for |
Shards | Shard[] | undefined | An array of JSON objects. Each object represents one shard and specifies the IDs of the shard, the shard's parent, and the shard that's adjacent to the shard's parent. Each object also contains the starting and ending hash keys and the starting and ending sequence numbers for the shard. |
Throws
Name | Fault | Details |
---|
Name | Fault | Details |
---|---|---|
AccessDeniedException | client | Specifies that you do not have the permissions required to perform this operation. |
ExpiredNextTokenException | client | The pagination token passed to the operation is expired. |
InvalidArgumentException | client | A specified parameter exceeds its restrictions, is not supported, or can't be used. For more information, see the returned message. |
LimitExceededException | client | The requested resource exceeds the maximum number allowed, or the number of concurrent stream requests exceeds the maximum number allowed. |
ResourceInUseException | client | The resource is not available for this operation. For successful operation, the resource must be in the |
ResourceNotFoundException | client | The requested resource could not be found. The stream might not be specified correctly. |
KinesisServiceException | Base exception class for all service exceptions from Kinesis service. |