All Products
Search
Document Center

Object Storage Service:put-cname

更新时间:Jun 26, 2025

Maps a custom domain name to a bucket.

Permissions

By default, an Alibaba Cloud account has full permissions. RAM users or RAM roles under an Alibaba Cloud account do not have any permissions by default. The Alibaba Cloud account or account administrator must grant operation permissions through RAM Policy or Bucket Policy.

API

Action

Definition

PutCname

oss:PutCname

Maps a custom domain name to a bucket.

yundun-cert:DescribeSSLCertificatePrivateKey

When mapping a custom domain name to a bucket, if a certificate is attached, these three permissions are required.

yundun-cert:DescribeSSLCertificatePublicKeyDetail

yundun-cert:CreateSSLCertificate

Command syntax

ossutil api put-cname --bucket value --cname-configuration value [flags]

Parameter

Type

Description

--bucket

string

The name of the bucket.

--cname-configuration

string

The container that stores the CNAME record.

Note

The put-cname command corresponds to the PutCname operation. For more information about the parameters in the PutCname operation, see PutCname.

--cname-configuration

The --cname-configuration option supports both XML and JSON formats. If the value of the option contains the file:// prefix, ossutil reads configurations from a configuration file.

  • XML format:

    <BucketCnameConfiguration>
      <Cname>
        <Domain>string</Domain>
      </Cname>
    </BucketCnameConfiguration>
  • JSON syntax:

    {
      "Cname": {
        "Domain": "string"
      }
    }
Note

For more information about supported global command-line options, see Global command-line options.

Examples

Attach the custom domain name example.com to the bucket examplebucket.

  • Create a configuration file named cname-configuration.xml and add the following code to the configuration file:

    <?xml version="1.0" encoding="UTF-8"?>
    <BucketCnameConfiguration>
      <Cname>
        <Domain>example.com</Domain>
      </Cname>
    </BucketCnameConfiguration>

    Sample command:

    ossutil api put-cname --bucket examplebucket --cname-configuration file://cname-configuration.xml
  • Create a configuration file named cname-configuration.json and add the following code to the configuration file:

    {
      "Cname": {
        "Domain": "example.com"
      }
    }

    Sample command:

    ossutil api put-cname --bucket examplebucket --cname-configuration file://cname-configuration.json
  • Configure parameters in the following command in the JSON format:

    ossutil api put-cname --bucket examplebucket --cname-configuration "{\"Cname\":{\"Domain\":\"example.com\"}}"

The following examples show how to attach a certificate to a bucket named examplebucket.

  • Create a configuration file named cname-configuration.xml and add the following code to the configuration file:

    <?xml version="1.0" encoding="UTF-8"?>
    <BucketCnameConfiguration>
      <Cname>
        <Domain>example.com</Domain>
        <CertificateConfiguration>
          <CertId>493****-cn-hangzhou</CertId>
          <Certificate>-----BEGIN CERTIFICATE----- MIIDhDCCAmwCCQCFs8ixARsyrDANBgkqhkiG9w0BAQsFADCBgzELMAkGA1UEBhMC **** -----END CERTIFICATE-----</Certificate>
          <PrivateKey>-----BEGIN RSA PRIVATE KEY-----\nMIIDhDCCAmwCCQCFs8ixARsyrDANBgkqhkiG9w0BAQsFADCBgzELMAkGA1UEBhMC****\n-----END RSA PRIVATE KEY-----</PrivateKey>
          <PreviousCertId>493****-cn-hangzhou</PreviousCertId>
          <Force>true</Force>
        </CertificateConfiguration>
      </Cname>
    </BucketCnameConfiguration>

    Sample command:

    ossutil api put-cname --bucket examplebucket --cname-configuration file://cname-configuration.xml
  • Create a configuration file named cname-configuration.json and add the following code to the configuration file:

    {
        "Cname": {
            "Domain": "example.com",
            "CertificateConfiguration": {
                "CertId": "493****-cn-hangzhou",
                "Certificate": "-----BEGIN CERTIFICATE-----\nMIIDhDCCAmwCCQCFs8ixARsyrDANBgkqhkiG9w0BAQsFADCBgzELMAkGA1UEBhMC****\n-----END CERTIFICATE-----",
                "PrivateKey": "-----BEGIN RSA PRIVATE KEY-----\nMIIDhDCCAmwCCQCFs8ixARsyrDANBgkqhkiG9w0BAQsFADCBgzELMAkGA1UEBhMC****\n-----END RSA PRIVATE KEY-----",
                "PreviousCertId": "493****-cn-hangzhou",
                "Force": true
            }
        }
    }

    Sample command:

    ossutil api put-cname --bucket examplebucket --cname-configuration file://cname-configuration.json