All Products
Search
Document Center

Key Management Service:Integration overview

Last Updated:Sep 18, 2026

In addition to a web console, Key Management Service (KMS) provides multiple programmatic integration methods, including OpenAPI online debugging, the Alibaba Cloud SDK, and Terraform, to help you develop and deploy your applications more efficiently.

Integration process

image

Version description

You can debug the API list for the 2016-01-20 version online. The string 2016-01-20 represents the API version number, not a date. The displayed data is the latest publicly available API data, and the APIs have continued to be updated since 2016-01-20. For information about how to view the API version, see View API versions.

Version

Description

2016-01-20

Recommended

Online debugging

To help developers quickly and efficiently learn and use Alibaba Cloud OpenAPI, Alibaba Cloud provides the OpenAPI portal. The portal integrates intelligent OpenAPI search, documentation, online debugging, SDK downloads, code samples, error diagnostics, and call statistics. You can use the OpenAPI portal to call the OpenAPIs of Alibaba Cloud services and view the request and response results. The portal also automatically generates SDK code samples to help you quickly use Alibaba Cloud services. For more information, see What is OpenAPI?.

KMS supports API debugging on the Alibaba Cloud OpenAPI portal. Before you begin, familiarize yourself with the API version, endpoints, and API parameters. After you log on to the OpenAPI portal with your Alibaba Cloud account, the portal uses your account for online OpenAPI debugging by default.

The API debugging entry is: https://next.api.alibabacloud.com/api/Kms/2016-01-20

After you log on to the OpenAPI portal, the left pane displays the KMS API list (such as DescribeRegions). The center area is used to set the input parameters for the API and click Send Request. The right pane shows information such as Documentation, Debugging Result, SDK Sample Code, and CLI Sample Code, as well as the definitions of the response parameters.

Endpoints

KMS supports two types of gateways: shared gateways and dedicated gateways. You can use shared gateways for both control-plane and data-plane operations, and use dedicated gateways for data-plane operations. Shared gateways can be accessed over the internet or a VPC, while dedicated gateways are accessed through the KMS private network. The two types of gateways use different endpoints. For more information about the differences between the two gateway types, see Alibaba Cloud SDK.

Shared gateway endpoint (also known as KMS service endpoint)

Important

To call cryptographic data-plane operations through a shared gateway, you must first enable public network access. For more information, see Access keys in a KMS instance over the public network.

Select the service endpoint based on the region where your resources reside to minimize latency. For example, in the China (Hangzhou) region, the public endpoint for KMS is kms.cn-hangzhou.aliyuncs.com, and the VPC endpoint is kms-vpc.cn-hangzhou.aliyuncs.com. For a complete list of endpoints, see Endpoints.

  • Public endpoints can be accessed globally.

  • VPC endpoints can be accessed only from within the corresponding Alibaba Cloud region and only over a VPC network. Advantages of VPC endpoints:

    • Enhanced security: VPC service endpoints are accessible only from within a VPC, providing improved security and privacy.

    • Faster response: Because VPC service endpoints operate over the internal VPC network, they typically deliver faster response times and avoid public network issues such as latency and bandwidth limits.

    • Lower cost: VPC service endpoints use internal network communication.

Dedicated gateway endpoint (also known as KMS instance endpoint)

The dedicated gateway is accessed through the KMS private network. The dedicated gateway endpoint format is <YOUR_KMS_INSTANCE_ID>.cryptoservice.kms.aliyuncs.com, for example, kst-hzz65f176a0ogplgq****.cryptoservice.kms.aliyuncs.com.

Note
  • Replace <YOUR_KMS_INSTANCE_ID> with the ID of the KMS instance that you actually use.

  • When you call data-plane operations through a dedicated gateway, you must add the instance CA certificate configuration during client initialization. For more information, see Initialize the client.

Authentication methods

When you use an Alibaba Cloud SDK to access OpenAPI through a shared gateway or a dedicated gateway, the authentication methods are the same. KMS supports RAM-based identity authentication methods such as AccessKey, STS token, RamRoleArn, and ECS instance RAM role. For more information, see Manage credentials and Identity, credentials, and authorization. For information about how to configure access policies, see Use RAM to implement access control.

AccessKey

Warning

By default, an Alibaba Cloud account has administrator permissions for all resources, which cannot be modified. To ensure resource security, we recommend that you use a RAM user to create an AccessKey pair and grant it only the necessary permissions.

  1. Log on to the RAM console. On the Users page, click the name of the target RAM user.

  2. On the Secret Management tab, in the AccessKey section, click Create AccessKey.

  3. Grant the RAM user permissions to access KMS.

    • Method 1: Configure an identity-based policy

      In the Actions column of the RAM user, click Grant Permission to attach a built-in system permission policy for KMS to the RAM user. For more information about the system permission policies for KMS, see System policies for KMS.

      Note

      You can also create custom permission policies. For more information, see Create a custom policy.

    • Method 2: Configure a resource-based policy

      KMS supports resource-based policies that grant access permissions for individual keys and secrets. You can use these policies to control which Alibaba Cloud accounts, RAM users, and RAM roles can manage or use KMS keys and secrets. For more information, see Key policies and Secret policies.

ECS RAM role

An ECS instance RAM role allows you to obtain a temporary access credential (STS token) from within an ECS instance to call KMS API operations, without needing to configure an AccessKey pair.

For more information, see Instance RAM roles.

  1. Log on to the RAM console and create a RAM role for a trusted Alibaba Cloud service.

    • Trusted Entity Type: Select Elastic Compute Service.

    • Trusted entity: Select Elastic Compute Service (ECS).

  2. Grant the RAM role permissions to access KMS.

    • Method 1: Configure an identity-based policy

      In the Actions column of the RAM role, click Grant Permission to attach a built-in system permission policy for KMS to the RAM role. For more information about the system permission policies for KMS, see System policies for KMS.

      Note

      You can also create custom permission policies. For more information, see Create a custom policy.

    • Method 2: Configure a resource-based policy

      KMS supports resource-based policies that grant access permissions for individual keys and secrets. You can use these policies to control which Alibaba Cloud accounts, RAM users, and RAM roles can manage or use KMS keys and secrets. For more information, see Key policies and Secret policies.

  3. Log on to the ECS console and attach the RAM role to an ECS instance.

STS Token

Security Token Service (STS) issues a temporary access credential, an STS token, to a RAM user or RAM role. This token allows access to KMS with specific permissions for a limited validity period. After the token expires, it automatically becomes invalid.

  1. Log on to the RAM console to create a RAM user or a RAM role. For more information, see Create a RAM user and Create a RAM role.

  2. Grant the AliyunSTSAssumeRoleAccess permission to the RAM user or RAM role. For more information, see Manage RAM user permissions and Grant permissions to a RAM role.

  3. Grant the RAM user or RAM role permissions to access KMS.

    • Method 1: Configure an identity-based policy

      In the Actions column of the RAM role or user, click Grant Permission to attach a built-in system permission policy for KMS. For more information about the system permission policies for KMS, see System policies for KMS.

      Note

      You can also create custom permission policies. For more information, see Create a custom policy.

    • Method 2: Configure a resource-based policy

      KMS supports resource-based policies that grant access permissions for individual keys and secrets. You can use these policies to control which Alibaba Cloud accounts, RAM users, and RAM roles can manage or use KMS keys and secrets. For more information, see Key policies and Secret policies.

  4. Use the RAM user or RAM role to call the STS AssumeRole operation to obtain a temporary STS access credential. For more information, see AssumeRole.

RamRoleArn

RAM users or cloud services can assume a role to obtain temporary permissions (STS token) instead of using long-term keys, which reduces the risk of key leaks. For example, in a temporary data processing task, a RAM user or cloud service temporarily assumes a role with a specific RamRoleArn. After the task is complete, the role permissions are revoked, minimizing the risk of exposure.

  1. Create a user AccessKey pair

    1. Log on to the RAM console. In the left-side navigation pane, choose Identities > Users. On the Users page, click the name of the target RAM user.

    2. Attach the AliyunSTSAssumeRoleAccess system policy or a custom policy that includes the sts:AssumeRole action to the RAM user.

    3. On the Secret Management tab, in the AccessKey section, click Create AccessKey.

  2. Create and authorize a RAM role:

    1. In the left-side navigation pane, choose Identities > Roles. On the Roles page, click Create Role. For more information, see Create a RAM role.

    2. Grant the RAM role permissions to access KMS.

      • Method 1: Configure an identity-based policy

        In the Actions column of the RAM role, click Grant Permission to attach a built-in system permission policy for KMS to the RAM role. For more information about the system permission policies for KMS, see System policies for KMS.

        Note

        You can also create custom permission policies. For more information, see Create a custom policy.

      • Method 2: Configure a resource-based policy

        KMS supports resource-based policies that grant access permissions for individual keys and secrets. You can use these policies to control which Alibaba Cloud accounts, RAM users, and RAM roles can manage or use KMS keys and secrets. For more information, see Key policies and Secret policies.

  3. Obtain the RamRoleArn of the target RAM role. For more information, see View the information about a RAM role.

    1. In the left-side navigation pane, choose Identities > Roles. On the Roles page, click the name of the target role.

    2. On the role details page, find the RamRoleArn in the ARN section.

      Note

      The RamRoleArn is the Alibaba Cloud Resource Name (ARN) of the RAM role to assume. The format is acs:ram::$accountID:role/$roleName, where $accountID is the Alibaba Cloud account ID and $roleName is the RAM role name.

Integration methods

Note

The SDK is the easiest and best-supported way to call OpenAPI. We recommend that you use the SDK.

Alibaba Cloud SDK

Alibaba Cloud provides SDKs for multiple programming languages (Java, C#, Go, Python, Node.js/TypeScript, PHP, C++, and more). The SDKs encapsulate the signature logic, timeout mechanism, and retry mechanism, and provide request and response objects for API calls, which simplifies development. For more information about the Alibaba Cloud SDK, see Alibaba Cloud SDK.

Alibaba Cloud CLI

Alibaba Cloud CLI (Alibaba Cloud Command Line Interface) is a unified command-line tool built on Alibaba Cloud OpenAPI. You can use Alibaba Cloud CLI to interact with Alibaba Cloud services and manage your Alibaba Cloud resources from a shell. You can enter commands to perform operations without relying on a graphical user interface (GUI). For more information, see What is Alibaba Cloud CLI. For information about how to obtain and use Alibaba Cloud CLI commands, see Get started with Alibaba Cloud CLI.

Terraform

Terraform is an open source tool that lets you securely and efficiently preview, provision, and manage cloud infrastructure and resources. It calls OpenAPI after converting templates into an internal data structure, and it supports multiple major cloud providers. Terraform automatically calculates resource differences and generates an execution plan. You can preview the impact of changes before applying them, which helps prevent accidental resource damage or service interruption. For more information, see What is Alibaba Cloud Terraform?. To quickly use Terraform to orchestrate Key Management Service, see Overview.

Only some KMS API operations are supported when you use Terraform to orchestrate and use Key Management Service.

Custom API call encapsulation

Native HTTP calls require you to implement the signature algorithm on your own, construct custom requests based on the API parameters, and initiate the HTTP calls. For information about the signature algorithm, see Signature mechanism. In addition to the required business parameters, you must also concatenate the common request parameters. For more information, see Common parameters. For a sample custom API call, see Request syntax and signature method V3.

Usage notes

  • KMS accepts requests only over HTTPS. TLS 1.0, 1.1, and 1.2 are supported. SSL v2 and SSL v3 are not supported.

  • The maximum queries per second (QPS) of a single Alibaba Cloud account varies by API. For details, see the QPS limit in the documentation of each API. For more information, see Throttling and quota management.

    Note

    All RAM users under a single Alibaba Cloud account share the QPS quota of that Alibaba Cloud account.

  • If an API call returns an error, check whether the request parameters and their values are correct based on the returned error code. For more information, see Common error codes.

  • You can record the RequestID returned by the API call or the SDK error message, and use Alibaba Cloud OpenAPI Diagnostics to perform self-service diagnostics.