Usar o DeleteBucketCors
com um AWS SDK ou a CLI
Os exemplos de código a seguir mostram como usar o DeleteBucketCors
.
- .NET
-
- AWS SDK for .NET
-
nota
Há mais no GitHub. Encontre o exemplo completo e saiba como configurar e executar no Repositório de exemplos de código da AWS
. /// <summary> /// Deletes a CORS configuration from an Amazon S3 bucket. /// </summary> /// <param name="client">The initialized Amazon S3 client object used /// to delete the CORS configuration from the bucket.</param> private static async Task DeleteCORSConfigurationAsync(AmazonS3Client client) { DeleteCORSConfigurationRequest request = new DeleteCORSConfigurationRequest() { BucketName = BucketName, }; await client.DeleteCORSConfigurationAsync(request); }
-
Para obter detalhes da API, consulte DeleteBucketCors na Referência da API AWS SDK for .NET.
-
- CLI
-
- AWS CLI
-
O seguinte comando exclui a configuração de compartilhamento de recursos de origem cruzada do bucket
my-bucket
:aws s3api delete-bucket-cors --bucket
my-bucket
-
Para obter detalhes da API, consulte DeleteBucketCors
na Referência de comandos da AWS CLI.
-
- Python
-
- SDK para Python (Boto3).
-
nota
Há mais no GitHub. Encontre o exemplo completo e saiba como configurar e executar no Repositório de exemplos de código da AWS
. class BucketWrapper: """Encapsulates S3 bucket actions.""" def __init__(self, bucket): """ :param bucket: A Boto3 Bucket resource. This is a high-level resource in Boto3 that wraps bucket actions in a class-like structure. """ self.bucket = bucket self.name = bucket.name def delete_cors(self): """ Delete the CORS rules from the bucket. :param bucket_name: The name of the bucket to update. """ try: self.bucket.Cors().delete() logger.info("Deleted CORS from bucket '%s'.", self.bucket.name) except ClientError: logger.exception("Couldn't delete CORS from bucket '%s'.", self.bucket.name) raise
-
Para obter detalhes da API, consulte DeleteBucketCors na Referência da API AWS SDK para Python (Boto3).
-
- Ruby
-
- SDK para Ruby
-
nota
Há mais no GitHub. Encontre o exemplo completo e saiba como configurar e executar no Repositório de exemplos de código da AWS
. require "aws-sdk-s3" # Wraps Amazon S3 bucket CORS configuration. class BucketCorsWrapper attr_reader :bucket_cors # @param bucket_cors [Aws::S3::BucketCors] A bucket CORS object configured with an existing bucket. def initialize(bucket_cors) @bucket_cors = bucket_cors end # Deletes the CORS configuration of a bucket. # # @return [Boolean] True if the CORS rules were deleted; otherwise, false. def delete_cors @bucket_cors.delete true rescue Aws::Errors::ServiceError => e puts "Couldn't delete CORS rules for #{@bucket_cors.bucket.name}. Here's why: #{e.message}" false end end
-
Para obter detalhes da API, consulte DeleteBucketCors na Referência da API AWS SDK for Ruby.
-
Para ver uma lista completa dos Guias do desenvolvedor de SDK da AWS e exemplos de código, consulte Usar este serviço com um AWS SDK. Este tópico também inclui informações sobre como começar e detalhes sobre versões anteriores do SDK.