Create an Intelligent Media Management (IMM) project by calling the CreateProject API with the Python SDK.
View API documentation
In the API overview, locate the CreateProject operation and review its required parameters and permissions.
Identity and permissions
Identity
-
You can call this API operation with an Alibaba Cloud account, a RAM user, or a RAM role. Identity differences are explained in Identity, credential, and authorization. This example uses a RAM user. In the RAM console, create a RAM user with API access only and record the AccessKey pair. Create a RAM user.
Authorization
-
Go to Users, and in the Actions column for the target RAM user, click Add Permissions.
-
In the Add Permissions panel, select AliyunIMMFullAccess and AliyunSTSAssumeRoleAccess.
Note-
AliyunIMMFullAccess: Grants full management permissions on IMM. Configure a service role for a project.
-
For custom policies, Configure permissions for RAM users.
-
-
Click Grant permissions.
Access credential
-
Temporary access credential: Use temporary credentials for scenarios requiring higher security, such as temporary application access. They expire automatically, reducing leakage risk, and support fine-grained permission control. Configure access credentials (Go SDK V1).
-
Long-term access credential: Avoid long-term credentials when possible. Use temporary credentials instead. If you need long-term credentials for convenience, rotate them every three months. Delete or disable leaked or unused credentials immediately. Configure access credentials (Go SDK V1).
Long-term AccessKey
-
An AccessKey can be generated when you create a RAM user.
-
Click the RAM user name to open the details page. On the Authentication tab, click Create AccessKey. Create AccessKey.
STS temporary credential
You can call this operation only as a RAM user or by assuming a RAM role, not with an Alibaba Cloud account.
-
Create a RAM user.
-
Grant the RAM user the
AliyunSTSAssumeRoleAccesspermission. -
As the RAM user, call the AssumeRole operation of Security Token Service (STS) to obtain a temporary access credential.
Using an STS token for API calls is more secure than using an AccessKey because it protects your long-term AccessKey from exposure. If you make multiple temporary calls to IMM, refresh the STS token manually.
Call the API
This example uses the Python SDK. Other language SDKs follow a similar pattern. IMM SDK.
Prepare the Python environment
Download and install Python 3.
To check your Python version, open a terminal and enter python --version.
Configure AccessKey environment variables
This example uses the ALIBABA_CLOUD_ACCESS_KEY_ID and ALIBABA_CLOUD_ACCESS_KEY_SECRET environment variables. You can use different variable names, such as OSS_ACCESS_KEY_ID and OSS_ACCESS_KEY_SECRET.
The AccessKey pair of an Alibaba Cloud account has permissions on all API operations. We recommend that you use the AccessKey pair of a RAM user to call API operations or perform routine O&M.
Set an Alibaba Cloud AccessKey in environment variables on Linux and macOS
This section uses the environment variables ALIBABA_CLOUD_ACCESS_KEY_ID and ALIBABA_CLOUD_ACCESS_KEY_SECRET as examples. You can replace the variable names as needed, for example, OSS_ACCESS_KEY_ID and OSS_ACCESS_KEY_SECRET.
Configure environment variables using the export command
A temporary environment variable set using the export command is valid only for the current session. The variable is cleared when the session ends. For long-term retention (LTR), add the export command to the startup configuration file of your operating system.
Configure the AccessKey ID and press Enter.
# Replace yourAccessKeyID with your AccessKey ID. export ALIBABA_CLOUD_ACCESS_KEY_ID=yourAccessKeyIDConfigure the AccessKey secret and press Enter.
# Replace yourAccessKeySecret with your AccessKey secret. export ALIBABA_CLOUD_ACCESS_KEY_SECRET=yourAccessKeySecretVerify the configuration.
Run the
echo $ALIBABA_CLOUD_ACCESS_KEY_IDcommand. If the command returns the correct AccessKey ID, the configuration is successful.
Set an Alibaba Cloud AccessKey in environment variables on Windows
This section uses the environment variables ALIBABA_CLOUD_ACCESS_KEY_ID and ALIBABA_CLOUD_ACCESS_KEY_SECRET as examples. You can replace the variable names as needed, for example, OSS_ACCESS_KEY_ID and OSS_ACCESS_KEY_SECRET.
Use the graphical user interface (GUI)
Procedure
The following steps describe how to set environment variables using the GUI in Windows 10.
On your desktop, right-click This PC and choose Properties > Advanced system settings > Environment Variables > New under System variables or User variables. Then, complete the configuration.
Variable
Example value
AccessKey ID
Variable name: ALIBABA_CLOUD_ACCESS_KEY_ID
Variable value: yourAccessKeyID
AccessKey Secret
Variable name: ALIBABA_CLOUD_ACCESS_KEY_SECRET
Variable value: yourAccessKeySecret
Test the configuration
Click Start (or use the Win+R keyboard shortcut), click Run, enter `cmd`, and then click OK (or press Enter) to open the command prompt. Run the
echo %ALIBABA_CLOUD_ACCESS_KEY_ID%andecho %ALIBABA_CLOUD_ACCESS_KEY_SECRET%commands. If the commands return the correct AccessKey, the configuration is successful.
Use the command prompt (CMD)
Procedure
Open the command prompt as an administrator and run the following commands to add new environment variables to the system.
setx ALIBABA_CLOUD_ACCESS_KEY_ID yourAccessKeyID /M setx ALIBABA_CLOUD_ACCESS_KEY_SECRET yourAccessKeySecret /MThe
/Mparameter indicates a system environment variable. You can omit this parameter when you set a user environment variable.Test the configuration
Click Start (or use the Win+R keyboard shortcut), click Run, enter `cmd`, and then click OK (or press Enter) to open the command prompt. Run the
echo %ALIBABA_CLOUD_ACCESS_KEY_ID%andecho %ALIBABA_CLOUD_ACCESS_KEY_SECRET%commands. If the commands return the correct AccessKey, the configuration is successful.
Using Windows PowerShell
In PowerShell, you can set new environment variables that are valid for all new sessions:
[System.Environment]::SetEnvironmentVariable('ALIBABA_CLOUD_ACCESS_KEY_ID', 'yourAccessKeyID', [System.EnvironmentVariableTarget]::User)
[System.Environment]::SetEnvironmentVariable('ALIBABA_CLOUD_ACCESS_KEY_SECRET', 'yourAccessKeySecret', [System.EnvironmentVariableTarget]::User)To set environment variables for all users, you must have administrative permissions:
[System.Environment]::SetEnvironmentVariable('ALIBABA_CLOUD_ACCESS_KEY_ID', 'yourAccessKeyID', [System.EnvironmentVariableTarget]::Machine)
[System.Environment]::SetEnvironmentVariable('ALIBABA_CLOUD_ACCESS_KEY_SECRET', 'yourAccessKeySecret', [System.EnvironmentVariableTarget]::Machine)You can set temporary environment variables that are valid only for the current session:
$env:ALIBABA_CLOUD_ACCESS_KEY_ID = "yourAccessKeyID"
$env:ALIBABA_CLOUD_ACCESS_KEY_SECRET = "yourAccessKeySecret"In PowerShell, run the Get-ChildItem env:ALIBABA_CLOUD_ACCESS_KEY_ID and Get-ChildItem env:ALIBABA_CLOUD_ACCESS_KEY_SECRET commands. If the commands return the correct AccessKey, the configuration is successful.
After you configure the environment variables, you may need to restart your development tools, such as integrated development environments (IDEs), or services for the new settings to take effect.
Configure STS token environment variables
Mac OS X/Linux/Unix
export IMM_ACCESS_KEY_ID=<ALIBABA_CLOUD_ACCESS_KEY_ID>
export IMM_ACCESS_KEY_SECRET=<ALIBABA_CLOUD_ACCESS_KEY_SECRET>
export IMM_SESSION_TOKEN=<ALIBABA_CLOUD_SECURITY_TOKEN>
Windows
set IMM_ACCESS_KEY_ID <ALIBABA_CLOUD_ACCESS_KEY_ID>
set IMM_ACCESS_KEY_SECRET <ALIBABA_CLOUD_ACCESS_KEY_SECRET>
set IMM_SESSION_TOKEN <ALIBABA_CLOUD_SECURITY_TOKEN>
Download the sample code and install dependencies
pip install alibabacloud_credentials
On the Parameter Configuration tab, set the required parameters, such as projectName.
pip install alibabacloud_tea_console
Decompress the sample code package locally and go to the alibabacloud_sample directory.
Run the sample code
Run the following command.
python sample.py
The following output is returned.
{
"headers":{
"date":"Thu, 10 Aug 2023 06:34:51 GMT",
"content-type":"application/json;charset=utf-8",
"content-length":"602",
"connection":"keep-alive",
"keep-alive":"timeout=25",
"access-control-allow-origin":"*",
"access-control-expose-headers":"*",
"x-acs-request-id":"2C489857-69E6-5974-B963-A7DF99EFFF43",
"x-acs-trace-id":"eccc35df82a086e7bb4f4fe778f****",
"etag":"6HYADxT6iVDNgQUq+wGO****"
},
"statusCode":200,
"body":{
"Project":{
"CreateTime":"2023-08-10T14:34:51.586696893+08:00",
"DatasetCount":0,
"DatasetMaxBindCount":10,
"DatasetMaxEntityCount":10000000000,
"DatasetMaxFileCount":100000000,
"DatasetMaxRelationCount":100000000000,
"DatasetMaxTotalFileSize":90000000000000000,
"Description":"",
"EngineConcurrency":200,
"FileCount":0,
"ProjectMaxDatasetCount":1000000000,
"ProjectName":"testproject",
"ProjectQueriesPerSecond":200,
"ServiceRole":"AliyunIMMDefaultRole",
"TemplateId":"Official:DefaultEmptyId",
"TotalFileSize":0,
"UpdateTime":"2023-08-10T14:34:51.586696977+08:00"
},
"RequestId":"2C489857-69E6-5974-B963-A7DF99EFFF43"
}
}