Skip to content
v2.278.0

CorsConfigurationProperty Struct ​

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 .

Example ​

ts
// The code below shows an example of how to instantiate this type.
// The values are placeholders you should change.
import { aws_s3 as s3 } from 'aws-cdk-lib';
const corsConfigurationProperty: s3.CfnBucket.CorsConfigurationProperty = {
  corsRules: [{
    allowedMethods: ['allowedMethods'],
    allowedOrigins: ['allowedOrigins'],

    // the properties below are optional
    allowedHeaders: ['allowedHeaders'],
    exposedHeaders: ['exposedHeaders'],
    id: 'id',
    maxAge: 123,
  }],
};
python
# The code below shows an example of how to instantiate this type.
# The values are placeholders you should change.
from aws_cdk import aws_s3 as s3

cors_configuration_property = s3.CfnBucket.CorsConfigurationProperty(
    cors_rules=[s3.CfnBucket.CorsRuleProperty(
        allowed_methods=["allowedMethods"],
        allowed_origins=["allowedOrigins"],

        # the properties below are optional
        allowed_headers=["allowedHeaders"],
        exposed_headers=["exposedHeaders"],
        id="id",
        max_age=123
    )]
)
java
// The code below shows an example of how to instantiate this type.
// The values are placeholders you should change.
import software.amazon.awscdk.services.s3.*;

CorsConfigurationProperty corsConfigurationProperty = CorsConfigurationProperty.builder()
        .corsRules(List.of(CorsRuleProperty.builder()
                .allowedMethods(List.of("allowedMethods"))
                .allowedOrigins(List.of("allowedOrigins"))

                // the properties below are optional
                .allowedHeaders(List.of("allowedHeaders"))
                .exposedHeaders(List.of("exposedHeaders"))
                .id("id")
                .maxAge(123)
                .build()))
        .build();
csharp
// Install: dotnet add package Amazon.CDK.Lib
// The code below shows an example of how to instantiate this type.
// The values are placeholders you should change.
using Amazon.CDK.AWS.S3;

var corsConfigurationProperty = new CorsConfigurationProperty {
    CorsRules = new [] { new CorsRuleProperty {
        AllowedMethods = new [] { "allowedMethods" },
        AllowedOrigins = new [] { "allowedOrigins" },

        // the properties below are optional
        AllowedHeaders = new [] { "allowedHeaders" },
        ExposedHeaders = new [] { "exposedHeaders" },
        Id = "id",
        MaxAge = 123
    } }
};
go
// Install: go get github.com/aws/aws-cdk-go/awscdk/v2
// The code below shows an example of how to instantiate this type.
// The values are placeholders you should change.
import "github.com/aws/aws-cdk-go/awscdk"

corsConfigurationProperty := &CorsConfigurationProperty{
	CorsRules: []interface{}{
		&CorsRuleProperty{
			AllowedMethods: []*string{
				jsii.String("allowedMethods"),
			},
			AllowedOrigins: []*string{
				jsii.String("allowedOrigins"),
			},

			// the properties below are optional
			AllowedHeaders: []*string{
				jsii.String("allowedHeaders"),
			},
			ExposedHeaders: []*string{
				jsii.String("exposedHeaders"),
			},
			Id: jsii.String("id"),
			MaxAge: jsii.Number(123),
		},
	},
}

Properties ​

corsRulesIResolvable | IResolvable | CfnBucket.CorsRuleProperty[]cors_rulestyping.Union[IResolvable, typing.List[typing.Union[IResolvable, CorsRuleProperty]]]corsRulesIResolvableCorsRulesIResolvableCorsRulesinterface{} 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.