AWS 文档 AWS SDK示例 GitHub 存储库中还有更多SDK示例
本文属于机器翻译版本。若本译文内容与英语原文存在差异,则一律以英文原文为准。
与 AWS SDK或DescribeStream
一起使用 CLI
以下代码示例演示如何使用 DescribeStream
。
- CLI
-
- AWS CLI
-
描述数据流
以下
describe-stream
示例将返回指定数据流的详细信息。aws kinesis describe-stream \ --stream-name
samplestream
输出:
{ "StreamDescription": { "Shards": [ { "ShardId": "shardId-000000000000", "HashKeyRange": { "StartingHashKey": "0", "EndingHashKey": "113427455640312821154458202477256070484" }, "SequenceNumberRange": { "StartingSequenceNumber": "49600871682957036442365024926191073437251060580128653314" } }, { "ShardId": "shardId-000000000001", "HashKeyRange": { "StartingHashKey": "113427455640312821154458202477256070485", "EndingHashKey": "226854911280625642308916404954512140969" }, "SequenceNumberRange": { "StartingSequenceNumber": "49600871682979337187563555549332609155523708941634633746" } }, { "ShardId": "shardId-000000000002", "HashKeyRange": { "StartingHashKey": "226854911280625642308916404954512140970", "EndingHashKey": "340282366920938463463374607431768211455" }, "SequenceNumberRange": { "StartingSequenceNumber": "49600871683001637932762086172474144873796357303140614178" } } ], "StreamARN": "arn:aws:kinesis:us-west-2:123456789012:stream/samplestream", "StreamName": "samplestream", "StreamStatus": "ACTIVE", "RetentionPeriodHours": 24, "EnhancedMonitoring": [ { "ShardLevelMetrics": [] } ], "EncryptionType": "NONE", "KeyId": null, "StreamCreationTimestamp": 1572297168.0 } }
有关更多信息,请参阅《Amazon Kinesis Data Streams 开发人员指南》中的创建和管理流。
-
有关API详细信息,请参阅 “DescribeStream AWS CLI
命令参考”。
-
- PowerShell
-
- 用于 PowerShell
-
示例 1:返回指定流的详细信息。
Get-KINStream -StreamName "mystream"
输出:
HasMoreShards : False RetentionPeriodHours : 24 Shards : {} StreamARN : arn:aws:kinesis:us-west-2:123456789012:stream/mystream StreamName : mystream StreamStatus : ACTIVE
-
有关API详细信息,请参阅 AWS Tools for PowerShell Cmdlet 参考DescribeStream中的。
-
- Python
-
- SDK适用于 Python (Boto3)
-
注意
还有更多相关信息 GitHub。查找完整示例,学习如何在 AWS 代码示例存储库
中进行设置和运行。 class KinesisStream: """Encapsulates a Kinesis stream.""" def __init__(self, kinesis_client): """ :param kinesis_client: A Boto3 Kinesis client. """ self.kinesis_client = kinesis_client self.name = None self.details = None self.stream_exists_waiter = kinesis_client.get_waiter("stream_exists") def describe(self, name): """ Gets metadata about a stream. :param name: The name of the stream. :return: Metadata about the stream. """ try: response = self.kinesis_client.describe_stream(StreamName=name) self.name = name self.details = response["StreamDescription"] logger.info("Got stream %s.", name) except ClientError: logger.exception("Couldn't get %s.", name) raise else: return self.details
-
有关API详细信息,请参阅DescribeStream中的 AWS SDKPython (Boto3) API 参考。
-
- Rust
-
- SDK对于 Rust
-
注意
还有更多相关信息 GitHub。查找完整示例,学习如何在 AWS 代码示例存储库
中进行设置和运行。 async fn show_stream(client: &Client, stream: &str) -> Result<(), Error> { let resp = client.describe_stream().stream_name(stream).send().await?; let desc = resp.stream_description.unwrap(); println!("Stream description:"); println!(" Name: {}:", desc.stream_name()); println!(" Status: {:?}", desc.stream_status()); println!(" Open shards: {:?}", desc.shards.len()); println!(" Retention (hours): {}", desc.retention_period_hours()); println!(" Encryption: {:?}", desc.encryption_type.unwrap()); Ok(()) }
-
有关API详细信息,请参见DescribeStream
中的 Rust AWS SDK API 参考。
-
- SAP ABAP
-
- SDK对于 SAP ABAP
-
注意
还有更多相关信息 GitHub。查找完整示例,学习如何在 AWS 代码示例存储库
中进行设置和运行。 TRY. oo_result = lo_kns->describestream( iv_streamname = iv_stream_name ). DATA(lt_stream_description) = oo_result->get_streamdescription( ). MESSAGE 'Streams retrieved.' TYPE 'I'. CATCH /aws1/cx_knslimitexceededex . MESSAGE 'The request processing has failed because of a limit exceed exception.' TYPE 'E'. CATCH /aws1/cx_knsresourcenotfoundex . MESSAGE 'Resource being accessed is not found.' TYPE 'E'. ENDTRY.
-
有关API详细信息,请参阅DescribeStream中的AWS SDK以供SAPABAPAPI参考。
-
DeregisterStreamConsumer
GetRecords