When you use Object Storage Service (OSS) together with CDN, you are charged outbound traffic fees and back-to-origin outbound traffic fees by CDN. If you want to use back-to-origin traffic plans to offset fees when you use OSS SDKs, you must replace the bucket domain name with the custom domain name that you configured for Alibaba Cloud CDN and add a CNAME record when you initiate OSS SDKs.

The following code provides examples on how to configure an accelerated domain name for CDN by using OSS SDKs in multiple programming languages:

// Enter the custom domain name that you configured for Alibaba Cloud CDN. Example: example.com. 
String endpoint = "https://example.com";
// The AccessKey pair of an Alibaba Cloud account has permissions on all API operations. Using these credentials to perform operations in OSS is a high-risk operation. We recommend that you use a RAM user to call API operations or perform routine O&M. To create a RAM user, log on to the RAM console. 
String accessKeyId = "yourAccessKeyId";
String accessKeySecret = "yourAccessKeySecret";

// Create a ClientConfiguration instance and modify the default parameters based on your business requirements. 
ClientBuilderConfiguration conf = new ClientBuilderConfiguration();
// Enable CNAME. CNAME is used to map the custom domain name to the bucket. 
conf.setSupportCname(true);

// Create an OSSClient instance. 
OSS ossClient = new OSSClientBuilder().build(endpoint, accessKeyId, accessKeySecret, conf);

// Shut down the OSSClient instance. 
ossClient.shutdown(); 
<?php
if (is_file(__DIR__ . '/../autoload.php')) {
    require_once __DIR__ . '/../autoload.php';
}
if (is_file(__DIR__ . '/../vendor/autoload.php')) {
    require_once __DIR__ . '/../vendor/autoload.php';
}

use OSS\OssClient;
use OSS\Core\OssException;

// The AccessKey pair of an Alibaba Cloud account has permissions on all API operations. Using these credentials to perform operations in OSS is a high-risk operation. We recommend that you use a RAM user to call API operations or perform routine O&M. To create a RAM user, log on to the RAM console. 
$accessKeyId = "yourAccessKeyId";
$accessKeySecret = "yourAccessKeySecret";
// Enter the custom domain name that you configured for Alibaba Cloud CDN. Example: example.com. 
$endpoint = "https://example.com";

try {
    // Enable CNAME. CNAME is used to map the custom domain name to the bucket. 
    $ossClient = new OssClient($accessKeyId, $accessKeySecret, $endpoint, true);
} catch (OssException $e) {
    print $e->getMessage();
}                    
# -*- coding: utf-8 -*-
import oss2

# The AccessKey pair of an Alibaba Cloud account has permissions on all API operations. Using these credentials to perform operations in OSS is a high-risk operation. We recommend that you use a RAM user to call API operations or perform routine O&M. To create a RAM user, log on to the RAM console. 
auth = oss2.Auth('yourAccessKeyId', 'yourAccessKeySecret')

# Enter the custom domain name that you configured for Alibaba Cloud CDN. Example: example.com. 
cname = 'http://example.com'

# Enable CNAME and use CNAME to bind the custom domain name to the bucket. 
bucket = oss2.Bucket(auth, cname, 'examplebucket', is_cname=True)                    
using Aliyun.OSS;
using Aliyun.OSS.Common;
// The AccessKey pair of an Alibaba Cloud account has permissions on all API operations. Using these credentials to perform operations in OSS is a high-risk operation. We recommend that you use a RAM user to call API operations or perform routine O&M. To create a RAM user, log on to the RAM console. 
const string accessKeyId = "yourAccessKeyId";
const string accessKeySecret = "yourAccessKeySecret";
// Enter the custom domain name that you configured for Alibaba Cloud CDN. Example: example.com. 
const string endpoint = "https://example.com";

// Create a ClientConfiguration instance and modify the default parameters based on your business requirements. 
var conf = new ClientConfiguration();
// Enable CNAME. CNAME is used to map the custom domain name to the bucket. 
conf.IsCname = true;

// Create an OSSClient instance. 
var client = new OssClient(endpoint, accessKeyId, accessKeySecret, conf);                    
import "github.com/aliyun/aliyun-oss-go-sdk/oss"
// Enter the custom domain name that you configured for Alibaba Cloud CDN. Example: example.com. 
// The AccessKey pair of an Alibaba Cloud account has permissions on all API operations. Using these credentials to perform operations in OSS is a high-risk operation. We recommend that you use a RAM user to call API operations or perform routine O&M. To create a RAM user, log on to the RAM console. 
// Enable CNAME by setting oss.UseCname to true. CNAME is used to map the custom domain name to the bucket. 
client, err := oss.New("https://example.com", "yourAccessKeyId", "yourAccessKeySecret", oss.UseCname(true))
if err != nil {
    fmt.Println("Error:", err)
    os.Exit(-1)
}            
#include "oss_api.h"
#include "aos_http_io.h"
/* Enter the custom domain name that you configured for Alibaba Cloud CDN. Example: example.com. */
const char *endpoint = "https://example.com";
/* The AccessKey pair of an Alibaba Cloud account has permissions on all API operations. Using these credentials to perform operations in OSS is a high-risk operation. We recommend that you use a RAM user to call API operations or perform routine O&M. To create a RAM user, log on to the RAM console. */
const char *access_key_id = "yourAccessKeyId";
const char *access_key_secret = "yourAccessKeySecret";
void init_options(oss_request_options_t *options) {
    options->config = oss_config_create(options->pool);
    /* Use a char* string to initialize the aos_string_t data type. */
    aos_str_set(&options->config->endpoint, endpoint);
    aos_str_set(&options->config->access_key_id, access_key_id);
    aos_str_set(&options->config->access_key_secret, access_key_secret);
    /* Enable CNAME and use CNAME to bind the custom domain name to the bucket. */
    options->config->is_cname = 1;
    options->ctl = aos_http_controller_create(options->pool, 0);
}
int main() {
    aos_pool_t *p;
    oss_request_options_t *options;
    /* Initialize global variables. */
    if (aos_http_io_initialize(NULL, 0) != AOSE_OK) {
        return -1;
    }
    /* Initialize the memory pool and options. */
    aos_pool_create(&p, NULL);
    options = oss_request_options_create(p);
    init_options(options); 
    /* Release the memory pool. This operation releases memory resources that are allocated for the request. */
    aos_pool_destroy(p);
    /* Release the allocated global resources. */
    aos_http_io_deinitialize();
    return 0;
}