Amazon Web Services 文档中描述的 Amazon Web Services 服务或功能可能因区域而异。要查看适用于中国区域的差异,请参阅
中国的 Amazon Web Services 服务入门
(PDF)。
本文属于机器翻译版本。若本译文内容与英语原文存在差异,则一律以英文原文为准。
Hello
以下代码示例展示了如何开始使用。
- Python
-
- 适用于 Python 的 SDK(Boto3)
-
import logging
import boto3
from botocore.exceptions import ClientError
logger = logging.getLogger(__name__)
def hello_kinesis():
"""
Lists Kinesis data streams with a limit of 10 and displays the results.
Use this example to verify that your environment is configured correctly.
"""
kinesis_client = boto3.client("kinesis")
print("Hello, Amazon Kinesis! Let's list some of your streams:\n")
try:
response = kinesis_client.list_streams(Limit=10)
stream_summaries = response.get("StreamSummaries", list())
if stream_summaries:
for summary in stream_summaries:
print(f" Stream: {summary['StreamName']}")
print(f"\nFound {len(stream_summaries)} stream(s).")
else:
print("No streams found in your account.")
except ClientError as err:
if err.response["Error"]["Code"] == "LimitExceededException":
logger.error("Request rate too high. Retry after a brief delay.")
else:
logger.error(
"Error listing streams: %s: %s",
err.response["Error"]["Code"],
err.response["Error"]["Message"],
)
raise
if __name__ == "__main__":
hello_kinesis()
如需查看完整清单 Amazon SDK 开发者指南和代码示例,请参阅 将此服务与 Amazon SDK。本主题还包括有关入门的信息以及有关先前的 SDK 版本的详细信息。