All Products
Search
Document Center

Simple Log Service:List projects

Last Updated:Dec 31, 2024

Call the ListProject API to retrieve a list of all projects in a specified resource group in the current region.

Prerequisites

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 value: 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.

  • If this parameter is not specified, a list of all projects in the region will be returned.

  • If this parameter is specified, a list of projects matching the fuzzy search term will be returned.

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