All Products
Search
Document Center

Simple Log Service:Query all machine groups in a specific project

Last Updated:Mar 19, 2025

You can call the ListMachineGroup operation to query all machine groups in a specific project.

Prerequisites

Parameters

def list_machine_group(self, project_name, offset=0, size=100):

Request parameters

Parameter

Type

Required

Description

project_name

String

Yes

The name of the project. The project in Simple Log Service is used to isolate the resources of different users and control access to specific resources. For more information, see Manage a project.

offset

int

No

The line from which the query starts. Default value: 0.

size

int

No

The number of entries per page. Default value: 100. Maximum value: 500.

Response parameters

For more information about the response parameters, see ListMachineGroup.

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 an instance of the LogClient class.
client = LogClient(endpoint, access_key_id, access_key_secret)

project_name = "proj-test-1"


def main():
    # Query all machine groups.
    res = client.list_machine_group(project_name)
    res.log_print()


if __name__ == '__main__':
    main()

 

Sample response

ListMachineGroupResponse:
headers: {'Server': 'AliyunSLS', 'Content-Type': 'application/json', 'Content-Length': '62', 'Connection': 'keep-alive', 'Access-Control-Allow-Origin': '*', 'Date': 'Tue, 15 Oct 2024 03:34:26 GMT', 'x-log-time': '1728963266', 'x-log-requestid': '670DE2C2B33AF4059C93****'}
count: 2
total: 2
machine_groups: ['group-1', 'group-2']

References