AWS SDK を使用して、Amazon S3 バケットから CORS ルールを削除する - AWS SDK コードサンプル

Doc AWS SDK Examples リポジトリには、他にも SDK の例があります。 AWS GitHub

翻訳は機械翻訳により提供されています。提供された翻訳内容と英語版の間で齟齬、不一致または矛盾がある場合、英語版が優先します。

AWS SDK を使用して、Amazon S3 バケットから CORS ルールを削除する

次のコード例は、S3 バケットから CORS ルールを削除する方法を示しています。

.NET
AWS SDK for .NET
注記

には他にもがあります GitHub。用例一覧を検索し、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); }
  • API の詳細については、「 API リファレンスDeleteBucketCors」の「」を参照してください。 AWS SDK for .NET

CLI
AWS CLI

次のコマンドは、my-bucket という名前のバケットから Cross-Origin Resource Sharing 設定を削除します。

aws s3api delete-bucket-cors --bucket my-bucket
  • API の詳細については、「 コマンドリファレンスDeleteBucketCors」の「」を参照してください。 AWS CLI

Python
SDK for Python (Boto3)
注記

には他にもがあります GitHub。用例一覧を検索し、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
  • API の詳細については、DeleteBucketCorsAWS「 SDK for Python (Boto3) API リファレンス」の「」を参照してください。

Ruby
SDK for Ruby
注記

には他にもがあります GitHub。用例一覧を検索し、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
  • API の詳細については、「 API リファレンスDeleteBucketCors」の「」を参照してください。 AWS SDK for Ruby