CreateProject APIを呼び出して、特定のリージョンにプロジェクトを作成します。
前提条件
Simple Log Serviceが有効化されています。 詳細については、「 Simple Log Serviceの有効化
Python用のSimple Log Service SDKが初期化されます。 詳細については、「Simple Log Service SDK For Pythonの初期化」をご参照ください。
パラメータ説明
def create_project(self, project_name, project_des, resource_group_id='', data_redundancy_type=None):リクエストパラメーター
パラメーター | 型 | 必須 / 任意 | 説明 |
project_name | String | 可 | プロジェクト名はAlibaba Cloudリージョン内でグローバルに一意である必要があり、作成後に変更することはできません。 命名規則は次のとおりです。
|
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関連ドキュメント
その他のコードサンプルについては、『aliyun-log-python-sdk on GitHub』をご参照ください。
プロジェクト関連のAPI操作の詳細については、以下のトピックを参照してください。