Query shards
Call the ListShards API to list all shards in a Logstore.
Prerequisites
-
Simple Log Service is activated. For more information, see Activate Simple Log Service.
-
The Simple Log Service SDK for Python is initialized. For more information, see Initialize Simple Log Service SDK for Python.
Parameters
def list_shards(self, project_name, logstore_name):
Request parameters
|
Parameter |
Type |
Required |
Description |
Example |
|
project_name |
String |
Yes |
Project name. |
ali-test-project |
|
logstore_name |
String |
Yes |
Logstore name. |
test-logstore |
Response parameters
For more information, see SplitShard.
Sample code
from aliyun.log import LogClient
import os
def main():
# In this example, the AccessKey ID and AccessKey secret are obtained from environment variables.
accessKeyId = os.environ.get('ALIBABA_CLOUD_ACCESS_KEY_ID', '')
accessKey = os.environ.get('ALIBABA_CLOUD_ACCESS_KEY_SECRET', '')
# The Simple Log Service endpoint.
endpoint = "cn-hangzhou.log.aliyuncs.com"
project_name = "ali-test-project"
logstore_name = "test-logstore"
client = LogClient(endpoint, accessKeyId, accessKey, "")
res = client.list_shards(project_name, logstore_name)
res.log_print()
if __name__ == '__main__':
main()
Sample response
ListShardResponse:
headers: {'Server': 'AliyunSLS', 'Content-Type': 'application/json', 'Content-Length': '335', 'Connection': 'keep-alive', 'Access-Control-Allow-Origin': '*', 'Date': 'Wed, 30 Oct 2024 06:21:26 GMT', 'x-log-time': '1730269286', 'x-log-requestid': '6721D066A5CBF5E0D241541F'}
res: [{'shardID': 0, 'status': 'readwrite', 'inclusiveBeginKey': '00000000000000000000000000000000', 'exclusiveEndKey': '80000000000000000000000000000000', 'createTime': 1716966695}, {'shardID': 1, 'status': 'readwrite', 'inclusiveBeginKey': '80000000000000000000000000000000', 'exclusiveEndKey': 'ffffffffffffffffffffffffffffffff', 'createTime': 1716966695}]
Process finished with exit code 0
References
-
For more information about using command-line interface (CLI) to manage shards, see the following topics:
-
For more information about shard management APIs, see the following topics:
-
The aliyun-log-python-sdk on GitHub repository provides additional samples.
-
Simple Log Service uses shards to manage the read and write capacities of logstores. For more information, see Shard.