Amazon Simple Storage Service

2021/03/10 - Amazon Simple Storage Service - 2 updated api methods

Changes  Adding ID element to the CORSRule schema

GetBucketCors (updated) Link ¶
Changes (response)
{'CORSRules': {'ID': 'string'}}

Returns the cors configuration information set for the bucket.

To use this operation, you must have permission to perform the s3:GetBucketCORS action. By default, the bucket owner has this permission and can grant it to others.

For more information about cors, see Enabling Cross-Origin Resource Sharing .

The following operations are related to GetBucketCors :

See also: AWS API Documentation

Request Syntax

client.get_bucket_cors(
    Bucket='string',
    ExpectedBucketOwner='string'
)
type Bucket

string

param Bucket

[REQUIRED]

The bucket name for which to get the cors configuration.

type ExpectedBucketOwner

string

param ExpectedBucketOwner

The account id of the expected bucket owner. If the bucket is owned by a different account, the request will fail with an HTTP 403 (Access Denied) error.

rtype

dict

returns

Response Syntax

{
    'CORSRules': [
        {
            'ID': 'string',
            'AllowedHeaders': [
                'string',
            ],
            'AllowedMethods': [
                'string',
            ],
            'AllowedOrigins': [
                'string',
            ],
            'ExposeHeaders': [
                'string',
            ],
            'MaxAgeSeconds': 123
        },
    ]
}

Response Structure

  • (dict) --

    • CORSRules (list) --

      A set of origins and methods (cross-origin access that you want to allow). You can add up to 100 rules to the configuration.

      • (dict) --

        Specifies a cross-origin access rule for an Amazon S3 bucket.

        • ID (string) --

          Unique identifier for the rule. The value cannot be longer than 255 characters.

        • AllowedHeaders (list) --

          Headers that are specified in the Access-Control-Request-Headers header. These headers are allowed in a preflight OPTIONS request. In response to any preflight OPTIONS request, Amazon S3 returns any requested headers that are allowed.

          • (string) --

        • AllowedMethods (list) --

          An HTTP method that you allow the origin to execute. Valid values are GET , PUT , HEAD , POST , and DELETE .

          • (string) --

        • AllowedOrigins (list) --

          One or more origins you want customers to be able to access the bucket from.

          • (string) --

        • ExposeHeaders (list) --

          One or more headers in the response that you want customers to be able to access from their applications (for example, from a JavaScript XMLHttpRequest object).

          • (string) --

        • MaxAgeSeconds (integer) --

          The time in seconds that your browser is to cache the preflight response for the specified resource.

PutBucketCors (updated) Link ¶
Changes (request)
{'CORSConfiguration': {'CORSRules': {'ID': 'string'}}}

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 Origin header must match AllowedOrigin elements.

  • The request method (for example, GET, PUT, HEAD, and so on) or the Access-Control-Request-Method header in case of a pre-flight OPTIONS request must be one of the AllowedMethod elements.

  • Every header specified in the Access-Control-Request-Headers request header of a pre-flight request must match an AllowedHeader element.

For more information about CORS, go to Enabling Cross-Origin Resource Sharing in the Amazon Simple Storage Service User Guide .

Related Resources

See also: AWS API Documentation

Request Syntax

client.put_bucket_cors(
    Bucket='string',
    CORSConfiguration={
        'CORSRules': [
            {
                'ID': 'string',
                'AllowedHeaders': [
                    'string',
                ],
                'AllowedMethods': [
                    'string',
                ],
                'AllowedOrigins': [
                    'string',
                ],
                'ExposeHeaders': [
                    'string',
                ],
                'MaxAgeSeconds': 123
            },
        ]
    },
    ContentMD5='string',
    ExpectedBucketOwner='string'
)
type Bucket

string

param Bucket

[REQUIRED]

Specifies the bucket impacted by the cors configuration.

type CORSConfiguration

dict

param 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 Simple Storage Service User Guide .

  • CORSRules (list) -- [REQUIRED]

    A set of origins and methods (cross-origin access that you want to allow). You can add up to 100 rules to the configuration.

    • (dict) --

      Specifies a cross-origin access rule for an Amazon S3 bucket.

      • ID (string) --

        Unique identifier for the rule. The value cannot be longer than 255 characters.

      • AllowedHeaders (list) --

        Headers that are specified in the Access-Control-Request-Headers header. These headers are allowed in a preflight OPTIONS request. In response to any preflight OPTIONS request, Amazon S3 returns any requested headers that are allowed.

        • (string) --

      • AllowedMethods (list) -- [REQUIRED]

        An HTTP method that you allow the origin to execute. Valid values are GET , PUT , HEAD , POST , and DELETE .

        • (string) --

      • AllowedOrigins (list) -- [REQUIRED]

        One or more origins you want customers to be able to access the bucket from.

        • (string) --

      • ExposeHeaders (list) --

        One or more headers in the response that you want customers to be able to access from their applications (for example, from a JavaScript XMLHttpRequest object).

        • (string) --

      • MaxAgeSeconds (integer) --

        The time in seconds that your browser is to cache the preflight response for the specified resource.

type ContentMD5

string

param ContentMD5

The base64-encoded 128-bit MD5 digest 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 AWS Command Line Interface (CLI) or AWS SDKs, this field is calculated automatically.

type ExpectedBucketOwner

string

param ExpectedBucketOwner

The account id of the expected bucket owner. If the bucket is owned by a different account, the request will fail with an HTTP 403 (Access Denied) error.

returns

None