S3 / Client / get_bucket_cors

get_bucket_cors#

S3.Client.get_bucket_cors(**kwargs)#

Returns the Cross-Origin Resource Sharing (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.

To use this API against an access point, provide the alias of the access point in place of the bucket name.

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

response = client.get_bucket_cors(
    Bucket='string',
    ExpectedBucketOwner='string'
)
Parameters:
  • Bucket (string) –

    [REQUIRED]

    The bucket name for which to get the cors configuration.

  • ExpectedBucketOwner (string) – The account ID of the expected bucket owner. If the bucket is owned by a different account, the request fails with the HTTP status code 403 Forbidden (access denied).

Return type:

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.

Examples

The following example returns cross-origin resource sharing (CORS) configuration set on a bucket.

response = client.get_bucket_cors(
    Bucket='examplebucket',
)

print(response)

Expected Output:

{
    'CORSRules': [
        {
            'AllowedHeaders': [
                'Authorization',
            ],
            'AllowedMethods': [
                'GET',
            ],
            'AllowedOrigins': [
                '*',
            ],
            'MaxAgeSeconds': 3000,
        },
    ],
    'ResponseMetadata': {
        '...': '...',
    },
}