すべてのプロダクト
Search
ドキュメントセンター

Simple Log Service:プロジェクトの作成

最終更新日:Jul 03, 2025

CreateProject APIを呼び出して、特定のリージョンにプロジェクトを作成します。

前提条件

パラメータ説明

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

リクエストパラメーター

パラメーター

必須 / 任意

説明

project_name

String

プロジェクト名はAlibaba Cloudリージョン内でグローバルに一意である必要があり、作成後に変更することはできません。 命名規則は次のとおりです。

  • プロジェクト名はグローバルに一意である必要があります。

  • 英小文字、数字、およびハイフン (-) のみを使用できます。

  • 先頭と末尾は小文字または数字である必要があります。

  • 長さは3〜63文字である必要があります。

project_des

String

プロジェクトの説明。 説明には、角括弧 (<>) 、アポストロフィ (') 、バックスラッシュ (\) 、二重引用符 (") 、または二重バックスラッシュ (\\) を含めることはできません。 最大64文字まで使用できます。

resource_group_id

String

任意

リソースグループID。 指定しない場合、デフォルトのリソースグループが使用されます。 詳細については、「リソースグループの作成」をご参照ください。

data_redundancy_type

String

任意

デフォルトでは、ローカル冗長ストレージ (LRS) が使用されます。 一部のリージョンでは、LRSとゾーン冗長ストレージ (ZRS) の両方が提供されます。 プロジェクトの作成後、冗長ストレージタイプを変更することはできません。 詳細については、「ストレージの冗長性」をご参照ください。 有効な値: LRSおよびZRS。

応答パラメーター

詳細については、「CreateProject」をご参照ください。

サンプルコード

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()

レスポンスの例

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

関連ドキュメント