This operation is not supported for directory buckets¶
Description¶
This operation is not supported for directory buckets.
Sets the cors configuration for your bucket. If the configuration exists, Amazon S3 replaces it.
To use this operation, you must be allowed to perform the s3:PutBucketCORS action. By default, the bucket owner has this permission and can grant it to others.
You set this configuration on a bucket so that the bucket can service cross-origin requests. For example, you might want to enable a request whose origin is http://www.example.com to access your Amazon S3 bucket at my.example.bucket.com by using the browser's XMLHttpRequest capability.
To enable cross-origin resource sharing (CORS) on a bucket, you add the cors subresource to the bucket. The cors subresource is an XML document in which you configure rules that identify origins and the HTTP methods that can be executed on your bucket. The document is limited to 64 KB in size.
When Amazon S3 receives a cross-origin request (or a pre-flight OPTIONS request) against a bucket, it evaluates the cors configuration on the bucket and uses the first CORSRule rule that matches the incoming browser request to enable a cross-origin request. For a rule to match, the following conditions must be met:
- The request's
Originheader must matchAllowedOriginelements. - The request method (for example, GET, PUT, HEAD, and so on) or the
Access-Control-Request-Methodheader in case of a pre-flightOPTIONSrequest must be one of theAllowedMethodelements. - Every header specified in the
Access-Control-Request-Headersrequest header of a pre-flight request must match anAllowedHeaderelement.
For more information about CORS, go to Enabling Cross-Origin Resource Sharing in the Amazon S3 User Guide.
The following operations are related to put_bucket_cors:
You must URL encode any signed header values that contain spaces. For example, if your header value is my file.txt, containing two spaces after my, you must URL encode this value to my%20%20file.txt.
Usage¶
Arguments¶
-
Bucket[required] Specifies the bucket impacted by the
corsconfiguration. -
CORSConfiguration[required] Describes the cross-origin access configuration for objects in an Amazon S3 bucket. For more information, see Enabling Cross-Origin Resource Sharing in the Amazon S3 User Guide.
-
ContentMD5The Base64 encoded 128-bit
MD5digest of the data. This header must be used as a message integrity check to verify that the request body was not corrupted in transit. For more information, go to RFC 1864.For requests made using the Amazon Web Services Command Line Interface (CLI) or Amazon Web Services SDKs, this field is calculated automatically.
-
ChecksumAlgorithmIndicates the algorithm used to create the checksum for the request when you use the SDK. This header will not provide any additional functionality if you don't use the SDK. When you send this header, there must be a corresponding
x-amz-checksumorx-amz-trailerheader sent. Otherwise, Amazon S3 fails the request with the HTTP status code400 Bad Request. For more information, see Checking object integrity in the Amazon S3 User Guide.If you provide an individual checksum, Amazon S3 ignores any provided
ChecksumAlgorithmparameter. -
ExpectedBucketOwnerThe account ID of the expected bucket owner. If the account ID that you provide does not match the actual owner of the bucket, the request fails with the HTTP status code
403 Forbidden(access denied).
Value¶
An empty list.
Request syntax¶
svc$put_bucket_cors(
Bucket = "string",
CORSConfiguration = list(
CORSRules = list(
list(
ID = "string",
AllowedHeaders = list(
"string"
),
AllowedMethods = list(
"string"
),
AllowedOrigins = list(
"string"
),
ExposeHeaders = list(
"string"
),
MaxAgeSeconds = 123
)
)
),
ContentMD5 = "string",
ChecksumAlgorithm = "CRC32"|"CRC32C"|"SHA1"|"SHA256"|"CRC64NVME"|"SHA512"|"MD5"|"XXHASH64"|"XXHASH3"|"XXHASH128",
ExpectedBucketOwner = "string"
)
Examples¶
# The following example enables PUT, POST, and DELETE requests from
# www.example.com, and enables GET requests from any domain.
svc$put_bucket_cors(
Bucket = "",
CORSConfiguration = list(
CORSRules = list(
list(
AllowedHeaders = list(
"*"
),
AllowedMethods = list(
"PUT",
"POST",
"DELETE"
),
AllowedOrigins = list(
"http://www.example.com"
),
ExposeHeaders = list(
"x-amz-server-side-encryption"
),
MaxAgeSeconds = 3000L
),
list(
AllowedHeaders = list(
"Authorization"
),
AllowedMethods = list(
"GET"
),
AllowedOrigins = list(
"*"
),
MaxAgeSeconds = 3000L
)
)
),
ContentMD5 = ""
)