List projects
Call the ListProject API to retrieve a list of all projects in a specified resource group in the current region.
Prerequisites
Simple Log Service is activated.
Simple Log Service SDK for Python is initialized.
Parameter description
def list_project(self, offset=0, size=100, project_name_pattern=None, resource_group_id=''):Request parameters
Parameter | Type | Required | Description |
offset | integer | No | The line from which the query starts. Default value: 0. |
size | integer | No | The number of entries per page. Default value: 100. Maximum: 500. |
project_name_pattern | string | No | Project name search term. For example, if you enter aliyun-project, the search result will include the projects named aliyun-project-sls and hangzhou-aliyun-project.
|
resource_group_id | string | No | Resource group ID. If not specified, the default resource group is used. For more information, see Create a resource group. |
Response parameters
For more informaton about the response parameters, see ListProject.
Sample code
from aliyun.log import LogClient
import os
# In this example, the AccessKey ID and AccessKey secret are obtained from environment variables.
access_key_id = os.environ.get('ALIBABA_CLOUD_ACCESS_KEY_ID', '')
access_key_secret = os.environ.get('ALIBABA_CLOUD_ACCESS_KEY_SECRET', '')
# The Simple Log Service endpoint.
endpoint = "cn-hangzhou.log.aliyuncs.com"
# Create a Simple Log Service client.
client = LogClient(endpoint, access_key_id, access_key_secret)
# List projects in the default resource group in the current region.
def main():
try:
response = client.list_project()
response.log_print()
except Exception as error:
print(error)
if __name__ == '__main__':
main()
References
For more code samples, see aliyun-log-python-sdk on GitHub.
For more information about project-related API operations, see the following topics: