Maps a custom domain name to a bucket.
Permissions
By default, an Alibaba Cloud account has full permissions. RAM users and RAM roles have no permissions by default. Grant permissions through RAM Policy or Bucket Policy.
| API | Action | Description |
|---|---|---|
| PutCname | oss:PutCname | Maps a custom domain name to a bucket. |
yundun-cert:DescribeSSLCertificatePrivateKey | — | Required when attaching an SSL certificate. |
yundun-cert:DescribeSSLCertificatePublicKeyDetail | — | Required when attaching an SSL certificate. |
yundun-cert:CreateSSLCertificate | — | Required when attaching an SSL certificate. |
Syntax
ossutil api put-cname --bucket <value> --cname-configuration <value> [flags]| Parameter | Type | Required | Description |
|---|---|---|---|
--bucket | string | Yes | The name of the bucket. |
--cname-configuration | string | Yes | The CNAME configuration. Accepts XML or JSON format, inline or from a file. |
The put-cname command corresponds to the PutCname API operation. For all supported parameters, see PutCname. For global flags, see Global command-line options.
--cname-configuration format
The --cname-configuration option accepts both XML and JSON. To load the configuration from a file, prefix the file path with file://.
XML:
<BucketCnameConfiguration>
<Cname>
<Domain>string</Domain>
</Cname>
</BucketCnameConfiguration>JSON:
{
"Cname": {
"Domain": "string"
}
}Examples
Map a custom domain name to a bucket
The following examples map the domain example.com to the bucket examplebucket.
Using an XML configuration file:
Create cname-configuration.xml:
<?xml version="1.0" encoding="UTF-8"?>
<BucketCnameConfiguration>
<Cname>
<Domain>example.com</Domain>
</Cname>
</BucketCnameConfiguration>ossutil api put-cname --bucket examplebucket --cname-configuration file://cname-configuration.xmlUsing a JSON configuration file:
Create cname-configuration.json:
{
"Cname": {
"Domain": "example.com"
}
}ossutil api put-cname --bucket examplebucket --cname-configuration file://cname-configuration.jsonInline JSON:
ossutil api put-cname --bucket examplebucket --cname-configuration "{\"Cname\":{\"Domain\":\"example.com\"}}"Attach an SSL certificate
The following examples attach an SSL certificate to the bucket examplebucket for the domain example.com.
Using an XML configuration file:
Create cname-configuration.xml:
<?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>ossutil api put-cname --bucket examplebucket --cname-configuration file://cname-configuration.xmlUsing a JSON configuration file:
Create cname-configuration.json:
{
"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
}
}
}ossutil api put-cname --bucket examplebucket --cname-configuration file://cname-configuration.json