tencent cloud

Cloud Object Storage

Release Notes and Announcements
Release Notes
Announcements
Product Introduction
Overview
Features
Use Cases
Strengths
Concepts
Regions and Access Endpoints
Specifications and Limits
Service Regions and Service Providers
Billing
Billing Overview
Billing Method
Billable Items
Free Tier
Billing Examples
Viewing and Downloading Bill
Payment Overdue
FAQs
Getting Started
Console
Getting Started with COSBrowser
User Guide
Creating Request
Bucket
Object
Data Management
Batch Operation
Global Acceleration
Monitoring and Alarms
Operations Center
Data Processing
Content Moderation
Smart Toolbox
Data Processing Workflow
Application Integration
User Tools
Tool Overview
Installation and Configuration of Environment
COSBrowser
COSCLI (Beta)
COSCMD
COS Migration
FTP Server
Hadoop
COSDistCp
HDFS TO COS
GooseFS-Lite
Online Tools
Diagnostic Tool
Use Cases
Overview
Access Control and Permission Management
Performance Optimization
Accessing COS with AWS S3 SDK
Data Disaster Recovery and Backup
Domain Name Management Practice
Image Processing
Audio/Video Practices
Workflow
Direct Data Upload
Content Moderation
Data Security
Data Verification
Big Data Practice
COS Cost Optimization Solutions
Using COS in the Third-party Applications
Migration Guide
Migrating Local Data to COS
Migrating Data from Third-Party Cloud Storage Service to COS
Migrating Data from URL to COS
Migrating Data Within COS
Migrating Data Between HDFS and COS
Data Lake Storage
Cloud Native Datalake Storage
Metadata Accelerator
GooseFS
Data Processing
Data Processing Overview
Image Processing
Media Processing
Content Moderation
File Processing Service
File Preview
Troubleshooting
Obtaining RequestId
Slow Upload over Public Network
403 Error for COS Access
Resource Access Error
POST Object Common Exceptions
API Documentation
Introduction
Common Request Headers
Common Response Headers
Error Codes
Request Signature
Action List
Service APIs
Bucket APIs
Object APIs
Batch Operation APIs
Data Processing APIs
Job and Workflow
Content Moderation APIs
Cloud Antivirus API
SDK Documentation
SDK Overview
Preparations
Android SDK
C SDK
C++ SDK
.NET(C#) SDK
Flutter SDK
Go SDK
iOS SDK
Java SDK
JavaScript SDK
Node.js SDK
PHP SDK
Python SDK
React Native SDK
Mini Program SDK
Error Codes
Harmony SDK
Endpoint SDK Quality Optimization
Security and Compliance
Data Disaster Recovery
Data Security
Cloud Access Management
FAQs
Popular Questions
General
Billing
Domain Name Compliance Issues
Bucket Configuration
Domain Names and CDN
Object Operations
Logging and Monitoring
Permission Management
Data Processing
Data Security
Pre-signed URL Issues
SDKs
Tools
APIs
Agreements
Service Level Agreement
Privacy Policy
Data Processing And Security Agreement
Contact Us
Glossary

Lifecycle

PDF
Focus Mode
Font Size
Last updated: 2025-10-14 10:52:01

Feature Overview

This document provides an overview of APIs and SDK code samples related to lifecycles.
API
Operation
Description
Setting a Lifecycle Configuration
Sets lifecycle management configuration for a bucket
Querying lifecycle
Queries the lifecycle management configuration of a bucket
Deleting lifecycle
Deletes the lifecycle management configuration of a bucket

Setting a Lifecycle Configuration

Note

Configuring the lifecycle settings for a bucket.

Method prototype

cos_status_t *cos_put_bucket_lifecycle(const cos_request_options_t *options,
const cos_string_t *bucket,
cos_list_t *lifecycle_rule_list,
cos_table_t **resp_headers);

Description

Parameter name
ParameterDescription
Local Disk Types
options
COS request options
Struct
bucket
Bucket name in the format of BucketName-APPID
String
lifecycle_rule_list
Lifecycle rule information
Struct
id
Lifecycle rule ID
String
prefix
Prefix to which the rule applies
String
status
Indicates whether the rule is enabled. Enumerated values: Enabled, Disabled
String
expire
Expiration attributes of the rule
Struct
days
Number of days before the deletion or transition operation is performed; number of days within which the multipart upload must be completed after it starts
Int
date
Date when the deletion or transition operation is performed
String
transition
Rule transition attribute, which indicates when the object is transited to Standard_IA or Archive
Struct
storage_class
Specify the target storage type for the Object transfer, enumerated values: Standard_IA, Archive. For more storage types, see Storage Class Overview.
String
abort
Maximum time length allowed for a multipart upload
Struct
resp_headers
Returns the HTTP response headers
Struct

Response description

Response Parameter
Description
Local Disk Types
code
Error Codes
Int
error_code
Error code
String
error_msg
Error code description
String
req_id
Request message ID
String

Sample

#include "cos_http_io.h"
#include "cos_api.h"
#include "cos_log.h"
#include <unistd.h>

// endpoint is the COS access domain name. For more information, see https://www.tencentcloud.com/document/product/436/6224.
static char TEST_COS_ENDPOINT[] = "cos.ap-guangzhou.myqcloud.com";
// A developer-owned secret ID/key used for the project. It can be obtained at https://console.tencentcloud.com/cam/capi.
static char *TEST_ACCESS_KEY_ID; //your secret_id
static char *TEST_ACCESS_KEY_SECRET; //your secret_key
// The only user-level resource identifier for COS access. It can be obtained at https://console.tencentcloud.com/cam/capi.
static char TEST_APPID[] = "<APPID>"; //your appid
// COS bucket name, in the format of [bucket]-[appid], for example mybucket-1253666666. It can be obtained at https://console.tencentcloud.com/cos5/bucket.
static char TEST_BUCKET_NAME[] = "<bucketname-appid>";

void log_status(cos_status_t *s)
{
cos_warn_log("status->code: %d", s->code);
if (s->error_code) cos_warn_log("status->error_code: %s", s->error_code);
if (s->error_msg) cos_warn_log("status->error_msg: %s", s->error_msg);
if (s->req_id) cos_warn_log("status->req_id: %s", s->req_id);
}

void init_test_config(cos_config_t *config, int is_cname)
{
cos_str_set(&config->endpoint, TEST_COS_ENDPOINT);
cos_str_set(&config->access_key_id, TEST_ACCESS_KEY_ID);
cos_str_set(&config->access_key_secret, TEST_ACCESS_KEY_SECRET);
cos_str_set(&config->appid, TEST_APPID);
config->is_cname = is_cname;
}

void init_test_request_options(cos_request_options_t *options, int is_cname)
{
options->config = cos_config_create(options->pool);
init_test_config(options->config, is_cname);
options->ctl = cos_http_controller_create(options->pool, 0);
}

void test_put_bucket_lifecycle()
{
cos_pool_t *p = NULL;
int is_cname = 0;
cos_status_t *s = NULL;
cos_request_options_t *options = NULL;
cos_string_t bucket;
cos_table_t *resp_headers = NULL;

// Initialize request options
cos_pool_create(&p, NULL);
options = cos_request_options_create(p);
init_test_request_options(options, is_cname);
cos_str_set(&bucket, TEST_BUCKET_NAME);

// Set lifecycle information
cos_list_t rule_list;
cos_list_init(&rule_list);
cos_lifecycle_rule_content_t *rule_content = NULL;

rule_content = cos_create_lifecycle_rule_content(p);
cos_str_set(&rule_content->id, "testrule1");
cos_str_set(&rule_content->prefix, "abc/");
cos_str_set(&rule_content->status, "Enabled");
rule_content->expire.days = 365;
cos_list_add_tail(&rule_content->node, &rule_list);

rule_content = cos_create_lifecycle_rule_content(p);
cos_str_set(&rule_content->id, "testrule2");
cos_str_set(&rule_content->prefix, "efg/");
cos_str_set(&rule_content->status, "Disabled");
cos_str_set(&rule_content->transition.storage_class, "Standard_IA");
rule_content->transition.days = 999;
cos_list_add_tail(&rule_content->node, &rule_list);

rule_content = cos_create_lifecycle_rule_content(p);
cos_str_set(&rule_content->id, "testrule3");
cos_str_set(&rule_content->prefix, "xxx/");
cos_str_set(&rule_content->status, "Enabled");
rule_content->abort.days = 1;
cos_list_add_tail(&rule_content->node, &rule_list);

// Set Lifecycle
s = cos_put_bucket_lifecycle(options, &bucket, &rule_list, &resp_headers);
log_status(s);

cos_pool_destroy(p);
}

int main(int argc, char *argv[])
{
// Get SECRETID and SECRETKEY from environment variables
TEST_ACCESS_KEY_ID = getenv("COS_SECRETID");
TEST_ACCESS_KEY_SECRET = getenv("COS_SECRETKEY");

if (cos_http_io_initialize(NULL, 0) != COSE_OK) {
exit(1);
}

//set log level, default COS_LOG_WARN
cos_log_set_level(COS_LOG_WARN);

//set log output, default stderr
cos_log_set_output(NULL);

test_put_bucket_lifecycle();

cos_http_io_deinitialize();

return 0;
}

Querying lifecycle

Note

This API is used to query the lifecycle management configuration of a bucket.

Method prototype

cos_status_t *cos_get_bucket_lifecycle(const cos_request_options_t *options,
const cos_string_t *bucket,
cos_list_t *lifecycle_rule_list,
cos_table_t **resp_headers);

Description

Parameter name
ParameterDescription
Local Disk Types
options
COS request options
Struct
bucket
Bucket name in the format of BucketName-APPID
String
lifecycle_rule_list
Lifecycle rule information
Struct
id
Lifecycle rule ID
String
prefix
Prefix to which the rule applies
String
status
Whether to enable the rule. Enumerated values: Enabled, Disabled
String
expire
Expiration attributes of the rule
Struct
days
Number of days before the deletion operation is performed
Int
date
Date when the deletion operation is performed
String
transition
Rule transition attribute, which indicates when the object is transited to Standard_IA or Archive
Struct
days
Number of days before the transition operation is performed
Int
date
Date when the transition operation is performed
String
storage_class
Specify the target storage type for the Object transfer, enumerated values: Standard_IA, Archive. For more storage types, see Storage Class Overview.
String
abort
Maximum time length allowed for a multipart upload
Struct
days
The number of days within which a multipart upload must be completed
Int
resp_headers
Returns the HTTP response headers
Struct

Response description

Response Parameter
Description
Local Disk Types
code
Error Codes
Int
error_code
Error code
String
error_msg
Error code description
String
req_id
Request message ID
String

Sample

#include "cos_http_io.h"
#include "cos_api.h"
#include "cos_log.h"
#include <unistd.h>

// endpoint is the COS access domain name. For more information, see https://www.tencentcloud.com/document/product/436/6224.
static char TEST_COS_ENDPOINT[] = "cos.ap-guangzhou.myqcloud.com";
// A developer-owned secret ID/key used for the project. It can be obtained at https://console.tencentcloud.com/cam/capi.
static char *TEST_ACCESS_KEY_ID; //your secret_id
static char *TEST_ACCESS_KEY_SECRET; //your secret_key
// The only user-level resource identifier for COS access. It can be obtained at https://console.tencentcloud.com/cam/capi.
static char TEST_APPID[] = "<APPID>"; //your appid
// COS bucket name, in the format of [bucket]-[appid], for example mybucket-1253666666. It can be obtained at https://console.tencentcloud.com/cos5/bucket.
static char TEST_BUCKET_NAME[] = "<bucketname-appid>";

void log_status(cos_status_t *s)
{
cos_warn_log("status->code: %d", s->code);
if (s->error_code) cos_warn_log("status->error_code: %s", s->error_code);
if (s->error_msg) cos_warn_log("status->error_msg: %s", s->error_msg);
if (s->req_id) cos_warn_log("status->req_id: %s", s->req_id);
}

void init_test_config(cos_config_t *config, int is_cname)
{
cos_str_set(&config->endpoint, TEST_COS_ENDPOINT);
cos_str_set(&config->access_key_id, TEST_ACCESS_KEY_ID);
cos_str_set(&config->access_key_secret, TEST_ACCESS_KEY_SECRET);
cos_str_set(&config->appid, TEST_APPID);
config->is_cname = is_cname;
}

void init_test_request_options(cos_request_options_t *options, int is_cname)
{
options->config = cos_config_create(options->pool);
init_test_config(options->config, is_cname);
options->ctl = cos_http_controller_create(options->pool, 0);
}

void test_get_bucket_lifecycle()
{
cos_pool_t *p = NULL;
int is_cname = 0;
cos_status_t *s = NULL;
cos_request_options_t *options = NULL;
cos_string_t bucket;
cos_table_t *resp_headers = NULL;

// Initialize request options
cos_pool_create(&p, NULL);
options = cos_request_options_create(p);
init_test_request_options(options, is_cname);
cos_str_set(&bucket, TEST_BUCKET_NAME);

// Query Lifecycle
cos_list_t rule_list_ret;
cos_list_init(&rule_list_ret);
s = cos_get_bucket_lifecycle(options, &bucket, &rule_list_ret, &resp_headers);
if (cos_status_is_ok(s)) {
printf("get bucket lifecycle succeeded\\n");
} else {
printf("get bucket lifecycle failed\\n");
}

cos_pool_destroy(p);
}

int main(int argc, char *argv[])
{
// Get SECRETID and SECRETKEY from environment variables
TEST_ACCESS_KEY_ID = getenv("COS_SECRETID");
TEST_ACCESS_KEY_SECRET = getenv("COS_SECRETKEY");

if (cos_http_io_initialize(NULL, 0) != COSE_OK) {
exit(1);
}

//set log level, default COS_LOG_WARN
cos_log_set_level(COS_LOG_WARN);

//set log output, default stderr
cos_log_set_output(NULL);

test_get_bucket_lifecycle();

cos_http_io_deinitialize();

return 0;
}

Deleting lifecycle

Note

This API is used to delete the lifecycle management configuration of a bucket.

Method prototype

cos_status_t *cos_delete_bucket_lifecycle(const cos_request_options_t *options,
const cos_string_t *bucket,
cos_table_t **resp_headers);

Description

Parameter name
ParameterDescription
Local Disk Types
options
COS request options
Struct
bucket
Bucket name in the format of BucketName-APPID
String
resp_headers
Returns the HTTP response headers
Struct

Response description

Response Parameter
Description
Local Disk Types
code
Error Codes
Int
error_code
Error code
String
error_msg
Error code description
String
req_id
Request message ID
String

Sample

#include "cos_http_io.h"
#include "cos_api.h"
#include "cos_log.h"
#include <unistd.h>

// endpoint is the COS access domain name. For more information, see https://www.tencentcloud.com/document/product/436/6224.
static char TEST_COS_ENDPOINT[] = "cos.ap-guangzhou.myqcloud.com";
// A developer-owned secret ID/key used for the project. It can be obtained at https://console.tencentcloud.com/cam/capi.
static char *TEST_ACCESS_KEY_ID; //your secret_id
static char *TEST_ACCESS_KEY_SECRET; //your secret_key
// The only user-level resource identifier for COS access. It can be obtained at https://console.tencentcloud.com/cam/capi.
static char TEST_APPID[] = "<APPID>"; //your appid
// COS bucket name, in the format of [bucket]-[appid], for example mybucket-1253666666. It can be obtained at https://console.tencentcloud.com/cos5/bucket.
static char TEST_BUCKET_NAME[] = "<bucketname-appid>";

void log_status(cos_status_t *s)
{
cos_warn_log("status->code: %d", s->code);
if (s->error_code) cos_warn_log("status->error_code: %s", s->error_code);
if (s->error_msg) cos_warn_log("status->error_msg: %s", s->error_msg);
if (s->req_id) cos_warn_log("status->req_id: %s", s->req_id);
}

void init_test_config(cos_config_t *config, int is_cname)
{
cos_str_set(&config->endpoint, TEST_COS_ENDPOINT);
cos_str_set(&config->access_key_id, TEST_ACCESS_KEY_ID);
cos_str_set(&config->access_key_secret, TEST_ACCESS_KEY_SECRET);
cos_str_set(&config->appid, TEST_APPID);
config->is_cname = is_cname;
}

void init_test_request_options(cos_request_options_t *options, int is_cname)
{
options->config = cos_config_create(options->pool);
init_test_config(options->config, is_cname);
options->ctl = cos_http_controller_create(options->pool, 0);
}

void test_delete_bucket_lifecycle()
{
cos_pool_t *p = NULL;
int is_cname = 0;
cos_status_t *s = NULL;
cos_request_options_t *options = NULL;
cos_string_t bucket;
cos_table_t *resp_headers = NULL;

// Initialize request options
cos_pool_create(&p, NULL);
options = cos_request_options_create(p);
init_test_request_options(options, is_cname);
cos_str_set(&bucket, TEST_BUCKET_NAME);

// Delete Lifecycle
s = cos_delete_bucket_lifecycle(options, &bucket, &resp_headers);
if (cos_status_is_ok(s)) {
printf("delete bucket lifecycle succeeded\\n");
} else {
printf("delete bucket lifecycle failed\\n");
}

cos_pool_destroy(p);
}

int main(int argc, char *argv[])
{
// Get SECRETID and SECRETKEY from environment variables
TEST_ACCESS_KEY_ID = getenv("COS_SECRETID");
TEST_ACCESS_KEY_SECRET = getenv("COS_SECRETKEY");

if (cos_http_io_initialize(NULL, 0) != COSE_OK) {
exit(1);
}

//set log level, default COS_LOG_WARN
cos_log_set_level(COS_LOG_WARN);

//set log output, default stderr
cos_log_set_output(NULL);

test_delete_bucket_lifecycle();

cos_http_io_deinitialize();

return 0;
}


Help and Support

Was this page helpful?

Help us improve! Rate your documentation experience in 5 mins.

Feedback