All Products
Search
Document Center

Object Storage Service:Get bucket information (C++ SDK)

Last Updated:Mar 20, 2026

Call GetBucketInfo to retrieve metadata about a bucket, including its region and creation date.

Prerequisites

Before you begin, make sure you have:

The examples below use the public endpoint for the China (Hangzhou) region. To access OSS from another Alibaba Cloud service in the same region, use the internal endpoint instead. For a full list of endpoints, see Regions and endpoints.

Get bucket information

The following example retrieves bucket information and prints the data redundancy type.

#include <alibabacloud/oss/OssClient.h>
using namespace AlibabaCloud::OSS;

int main(void)
{
    /* Set the endpoint of the region where the bucket is located.
       Example: https://oss-cn-hangzhou.aliyuncs.com for China (Hangzhou). */
    std::string Endpoint = "yourEndpoint";

    /* Set the region ID. Example: cn-hangzhou. */
    std::string Region = "yourRegion";

    /* Set the bucket name. Example: examplebucket. */
    std::string BucketName = "examplebucket";

    /* Initialize network resources. */
    InitializeSdk();

    ClientConfiguration conf;
    conf.signatureVersion = SignatureVersionType::V4;

    /* Load credentials from environment variables OSS_ACCESS_KEY_ID and OSS_ACCESS_KEY_SECRET. */
    auto credentialsProvider = std::make_shared<EnvironmentVariableCredentialsProvider>();
    OssClient client(Endpoint, credentialsProvider, conf);
    client.SetRegion(Region);

    /* Submit the request. */
    GetBucketInfoRequest request(BucketName);
    auto outcome = client.GetBucketInfo(request);

    if (!outcome.isSuccess()) {
        std::cout << "GetBucketInfo failed"
                  << " | code: "      << outcome.error().Code()
                  << " | message: "   << outcome.error().Message()
                  << " | requestId: " << outcome.error().RequestId()
                  << std::endl;
        ShutdownSdk();
        return -1;
    }

    /* Check the data redundancy type of the bucket. */
    std::cout << "GetBucketInfo succeeded | DataRedundancyType: "
              << static_cast<int>(outcome.result().DataRedundancyType())
              << std::endl;

    /* Release network resources. */
    ShutdownSdk();
    return 0;
}

References

For the complete list of request parameters and response fields, see GetBucketInfo.