All Products
Search
Document Center

Intelligent Media Management:IMM API integration

Last Updated:Dec 17, 2024

This topic provides a complete example on how to use the IMM API to create an Intelligent Media Management (IMM) project.

View API documentation

The CreateProject operation allows you to create an IMM project. For more information about the operation, see CreateProject. For more information about IMM API operations, see List of operations by function.

User identities and permissions

Identities

  • You can call API operations by using an Alibaba Cloud account or a Resource Access Management (RAM) role, or as a RAM user. For more information about the differences between the identities, see Identity, credential, and authorization. In this example, a RAM user is used to call the API operation. In the RAM console, create a RAM user that supports only API-based access, and record the AccessKey pair of the RAM user. For more information, see Create a RAM user.

Authorization

  1. On the Users page of the RAM console, find the RAM user and click Add Permissions in the Actions column.

  2. In the Policy section, select AliyunIMMFullAccess and AliyunSTSAssumeRoleAccess.

    Note
  3. Click Grant permissions.

Credentials

  • Temporary access credentials: For scenarios that require high security, such as temporary access authorization of applications to access OSS, we recommend that you use temporary access credentials. Temporary access credentials are valid within a specific period of time, which helps prevent credential leaks. Temporary access credentials support fine-grained access control. This helps effectively prevent security risks caused by excessive permissions. For more information, see Configure access credentials.

  • Long-term access credentials: To ensure data security, we recommend that you do not use long-term access credentials. For scenarios that require convenience, long-term access credentials eliminate the need for multiple refreshes within a long period of time. We recommend that you change your long-term access credentials every three months to ensure account security. If long-term access credentials are leaked or no longer used, you must delete or disable the long-term access credentials at the earliest opportunity to reduce security risks. For more information, see Configure access credentials.

Obtain a long-term AccessKey pair

  1. By default, an AccessKey pair is generated when you create a RAM user. You can directly use the AccessKey pair.

  2. You can also manually create an AccessKey pair for a RAM user by going to the RAM user details page and clicking Create AccessKey on the Authentication tab. For more information, see Create an AccessKey pair.

Obtain temporary access credentials from STS

Important

You can call the AssumeRole operation only as a RAM user or a RAM role. You cannot use an Alibaba Cloud account to call the operation.

  1. Create a RAM user.

    For more information, see Create a RAM user.

  2. Attach the AliyunSTSAssumeRoleAccess policy to the RAM user.

    For more information, see Grant permissions to a RAM user.

  3. Call the AssumeRole operation of Security Token Service (STS) as the RAM user to obtain temporary access credentials.

    For more information, see AssumeRole.

Note

Using temporary access credentials provided by STS is safer than directly using an AccessKey pair to call the operation. If you need to access IMM multiple times by using temporary access credentials, you must manually refresh the STS token.

Call the API operation

This section describes how to call the API operation by using IMM SDK for Python. You can use IMM SDKs for other programming languages to call the API operation in a similar way. For more information, see IMM SDK.

Prepare the Python environment

Download and install Python 3.

Note

To check the Python version, enter python --version in the terminal and press Enter.

Configure environment variables to store the AccessKey pair

After you create an AccessKey pair, we recommend that you configure environment variables for the AccessKey pair (AccessKey ID and AccessKey secret).

Important

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.

Configure an AccessKey pair in the environment variables on Linux and macOS

In this example, the ALIBABA_CLOUD_ACCESS_KEY_ID and ALIBABA_CLOUD_ACCESS_KEY_SECRET environment variables are configured. You can use different variable names, such as OSS_ACCESS_KEY_ID and OSS_ACCESS_KEY_SECRET.

Configure environment variables by using the export command

Important

The temporary environment variables configured by using the export command are valid only for the current session. After you exit the session, the configured environment variables become invalid. To configure permanent environment variables, you can add the export command to the startup configuration file of the corresponding operating system.

  • Configure the AccessKey ID and press Enter.

    # Replace <ACCESS_KEY_ID> with your AccessKey ID. 
    export ALIBABA_CLOUD_ACCESS_KEY_ID=<ACCESS_KEY_ID>
  • Configure the AccessKey secret and press Enter.

    # Replace <ACCESS_KEY_SECRET> with your AccessKey secret. 
    export ALIBABA_CLOUD_ACCESS_KEY_SECRET=<ACCESS_KEY_SECRET>
  • Check whether the configuration is successful.

    Run the echo $ALIBABA_CLOUD_ACCESS_KEY_ID command. If the valid AccessKey ID is returned, the environment variables are configured.

Windows

This section provides examples on how to configure the ALIBABA_CLOUD_ACCESS_KEY_ID and ALIBABA_CLOUD_ACCESS_KEY_SECRET environment variables:

Use GUI

  • Procedure

    If you want to use GUI to configure environment variables in Windows 10, perform the following steps:

    On the Windows desktop, right-click This PC and select Properties. On the page that appears, click Advanced system settings. In the System Properties dialog box, click Environment Variables on the Advanced tab. In the Environment Variables dialog box, click New in the User variables or System variables section. Then, configure the variables described in the following table.

    Variable

    Example

    AccessKey ID

    • Variable name: ALIBABA_CLOUD_ACCESS_KEY_ID

    • Variable value: LTAI4GDty8ab9W4Y1D****

    AccessKey Secret

    • Variable name: ALIBABA_CLOUD_ACCESS_KEY_SECRET

    • Variable value: IrVTNZNy5yQelTETg0cZML3TQn****

  • Check whether the configuration is successful.

    On the Windows desktop, click Start or press Win + R. In the Run dialog box, enter cmd. Then, click OK or press Enter. On the page that appears, run the echo %ALIBABA_CLOUD_ACCESS_KEY_ID% and echo %ALIBABA_CLOUD_ACCESS_KEY_SECRET% commands. If the valid AccessKey pair is returned, the configuration is successful.

Use CMD

  • Procedure

    Open a Command Prompt window as an administrator and run the following commands to add environment variables in the operating system:

    setx ALIBABA_CLOUD_ACCESS_KEY_ID LTAI4GDty8ab9W4Y1D**** /M
    setx ALIBABA_CLOUD_ACCESS_KEY_SECRET IrVTNZNy5yQelTETg0cZML3TQn**** /M

    /M indicates that the environment variable is of system level. You can choose not to use this parameter when you configure a user-level environment variable.

  • Check whether the configuration is successful.

    On the Windows desktop, click Start or press Win + R. In the Run dialog box, enter cmd. Then, click OK or press Enter. On the page that appears, run the echo %ALIBABA_CLOUD_ACCESS_KEY_ID% and echo %ALIBABA_CLOUD_ACCESS_KEY_SECRET% commands. If the valid AccessKey pair is returned, the configuration is successful.

Use Windows PowerShell

In PowerShell, configure new environment variables. The environment variables apply to all new sessions.

[System.Environment]::SetEnvironmentVariable('ALIBABA_CLOUD_ACCESS_KEY_ID', 'LTAI4GDty8ab9W4Y1D****', [System.EnvironmentVariableTarget]::User)
[System.Environment]::SetEnvironmentVariable('ALIBABA_CLOUD_ACCESS_KEY_SECRET', 'IrVTNZNy5yQelTETg0cZML3TQn****', [System.EnvironmentVariableTarget]::User)

Configure environment variables for all users. You must run the following commands as an administrator.

[System.Environment]::SetEnvironmentVariable('ALIBABA_CLOUD_ACCESS_KEY_ID', 'LTAI4GDty8ab9W4Y1D****', [System.EnvironmentVariableTarget]::Machine)
[System.Environment]::SetEnvironmentVariable('ALIBABA_CLOUD_ACCESS_KEY_SECRET', 'IrVTNZNy5yQelTETg0cZML3TQn****', [System.EnvironmentVariableTarget]::Machine)

Configure temporary environment variables. The environment variables apply only to the current session.

$env:ALIBABA_CLOUD_ACCESS_KEY_ID = "LTAI4GDty8ab9W4Y1D****"
$env:ALIBABA_CLOUD_ACCESS_KEY_SECRET = "IrVTNZNy5yQelTETg0cZML3TQn****"

In PowerShell, run the Get-ChildItem env:ALIBABA_CLOUD_ACCESS_KEY_ID and Get-ChildItem env:ALIBABA_CLOUD_ACCESS_KEY_SECRET commands. If the valid AccessKey pair is returned, the configuration is successful.

Configure environment variables to store temporary access credentials

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 Parameters tab, configure the required parameters. For example, specify a project name. 

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 in the terminal:

python sample.py

The following sample 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"
    }
}