Todos os produtos
Search
Central de documentação

Object Storage Service:Criar buckets com o OSS SDK for Python 1.0

Última atualização: Jul 03, 2026

Um bucket é um contêiner para armazenar objetos. Todos os objetos devem ser armazenados em um bucket. Este tópico descreve como criar um bucket.

Observações de uso

  • O código de exemplo deste tópico usa o ID da região cn-hangzhou, correspondente à região China (Hangzhou). Por padrão, o acesso aos recursos do bucket ocorre pelo endpoint público. Para acessar os recursos do bucket a partir de outros serviços da Alibaba Cloud na mesma região, use um endpoint interno. Para mais informações sobre regiões e endpoints do OSS, consulte Regiões e endpoints.

Exemplos

O código de exemplo a seguir mostra como criar um bucket chamado examplebucket:

# -*- 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 operations and maintenance. To create a RAM user, log on to the RAM console.
auth = oss2.Auth('yourAccessKeyId', 'yourAccessKeySecret')
# Specify the endpoint of the region in which the bucket is located. For example, if the bucket is located in the China (Hangzhou) region, set the endpoint to https://oss-cn-hangzhou.aliyuncs.com.
# Specify the name of the bucket. Example: examplebucket.
bucket = oss2.Bucket(auth, 'https://oss-cn-hangzhou.aliyuncs.com', 'examplebucket')

# Create the bucket. 
# The following sample code provides an example on how to specify the storage class, access control list (ACL), and redundancy type when you create the bucket. 
# In this example, the storage class is Standard, the ACL is private, and the redundancy type is zone-redundant storage (ZRS). 
# bucketConfig = oss2.models.BucketCreateConfig(oss2.BUCKET_STORAGE_CLASS_STANDARD, oss2.BUCKET_DATA_REDUNDANCY_TYPE_ZRS)
# bucket.create_bucket(oss2.BUCKET_ACL_PRIVATE, bucketConfig)
bucket.create_bucket()

Referências

  • Para obter o código de exemplo completo sobre criação de buckets, visite o GitHub.

  • Para mais informações sobre a operação de API de criação de buckets, consulte PutBucket.