All Products
Search
Document Center

Simple Log Service:Create a project

Last Updated:Dec 02, 2024

Call the CreateProject API to create a project in a specific region.

Prerequisites

Parameter description

def create_project(self, project_name, project_des, resource_group_id='', data_redundancy_type=None):

Request parameters

Parameter

Type

Required

Description

project_name

String

Yes

The project name must be globally unique within an Alibaba Cloud region and cannot be modified after creation. The naming conventions are as follows:

  • The project name must be globally unique.

  • It can contain only lowercase letters, digits, and hyphens (-).

  • It must start and end with a lowercase letter or digit.

  • It must be 3 to 63 characters in length.

project_des

String

Yes

Description of the project. The description must not contain angle brackets (<>), apostrophes ('), backslashes (\), double quotes ("), or double backslashes (\\). It can contain up to 64 characters.

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.

data_redundancy_type

String

No

By default, locally redundant storage (LRS) is used. Some regions offer both LRS and zone-redundant storage (ZRS). The redundancy storage type cannot be changed after the project is created. For more information, see Storage redundancy. Valid values: LRS and ZRS.

Response parameters

For more information, see CreateProject.

Sample code

from aliyun.log import LogClient
import os

# 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. In this example, the Simple Log Service endpoint for the China (Hangzhou) region is used. Replace the parameter value with the actual endpoint.
endpoint = "cn-hangzhou.log.aliyuncs.com"
# Create a Simple Log Service client.
client = LogClient(endpoint, accessKeyId, accessKey)

# The name of the project.
project_name = "slsproject-1"

# The description of the project. project_des="" specifies that the description of the project is left empty.
project_des = "this is a project created from ide."


# Call the create_project API. If no exception is thrown, the execution is successful.
def main():
    try:
        res = client.create_project(project_name, project_des)
        res.log_print()
    except Exception as error:
        print(error)


if __name__ == '__main__':
    main()

Sample response

CreateProjectResponse:
headers: {'Server': 'AliyunSLS', 'Content-Length': '0', 'Connection': 'keep-alive', 'Access-Control-Allow-Origin': '*', 'Date': 'Wed, 20 Nov 2024 06:25:28 GMT', 'x-log-time': '1732083928', 'x-log-requestid': '673D80D8E9F1E778CD32****'}

Process finished with exit code 0

References