aws logo
AWS Classic v5.41.0, May 15 23

aws.s3.BucketCorsConfigurationV2

Explore with Pulumi AI

Provides an S3 bucket CORS configuration resource. For more information about CORS, go to Enabling Cross-Origin Resource Sharing in the Amazon S3 User Guide.

NOTE: S3 Buckets only support a single CORS configuration. Declaring multiple aws.s3.BucketCorsConfigurationV2 resources to the same S3 Bucket will cause a perpetual difference in configuration.

Example Usage

using System.Collections.Generic;
using System.Linq;
using Pulumi;
using Aws = Pulumi.Aws;

return await Deployment.RunAsync(() => 
{
    var exampleBucketV2 = new Aws.S3.BucketV2("exampleBucketV2");

    var exampleBucketCorsConfigurationV2 = new Aws.S3.BucketCorsConfigurationV2("exampleBucketCorsConfigurationV2", new()
    {
        Bucket = exampleBucketV2.Id,
        CorsRules = new[]
        {
            new Aws.S3.Inputs.BucketCorsConfigurationV2CorsRuleArgs
            {
                AllowedHeaders = new[]
                {
                    "*",
                },
                AllowedMethods = new[]
                {
                    "PUT",
                    "POST",
                },
                AllowedOrigins = new[]
                {
                    "https://s3-website-test.domain.example",
                },
                ExposeHeaders = new[]
                {
                    "ETag",
                },
                MaxAgeSeconds = 3000,
            },
            new Aws.S3.Inputs.BucketCorsConfigurationV2CorsRuleArgs
            {
                AllowedMethods = new[]
                {
                    "GET",
                },
                AllowedOrigins = new[]
                {
                    "*",
                },
            },
        },
    });

});
package main

import (
	"github.com/pulumi/pulumi-aws/sdk/v5/go/aws/s3"
	"github.com/pulumi/pulumi/sdk/v3/go/pulumi"
)

func main() {
	pulumi.Run(func(ctx *pulumi.Context) error {
		exampleBucketV2, err := s3.NewBucketV2(ctx, "exampleBucketV2", nil)
		if err != nil {
			return err
		}
		_, err = s3.NewBucketCorsConfigurationV2(ctx, "exampleBucketCorsConfigurationV2", &s3.BucketCorsConfigurationV2Args{
			Bucket: exampleBucketV2.ID(),
			CorsRules: s3.BucketCorsConfigurationV2CorsRuleArray{
				&s3.BucketCorsConfigurationV2CorsRuleArgs{
					AllowedHeaders: pulumi.StringArray{
						pulumi.String("*"),
					},
					AllowedMethods: pulumi.StringArray{
						pulumi.String("PUT"),
						pulumi.String("POST"),
					},
					AllowedOrigins: pulumi.StringArray{
						pulumi.String("https://s3-website-test.domain.example"),
					},
					ExposeHeaders: pulumi.StringArray{
						pulumi.String("ETag"),
					},
					MaxAgeSeconds: pulumi.Int(3000),
				},
				&s3.BucketCorsConfigurationV2CorsRuleArgs{
					AllowedMethods: pulumi.StringArray{
						pulumi.String("GET"),
					},
					AllowedOrigins: pulumi.StringArray{
						pulumi.String("*"),
					},
				},
			},
		})
		if err != nil {
			return err
		}
		return nil
	})
}
package generated_program;

import com.pulumi.Context;
import com.pulumi.Pulumi;
import com.pulumi.core.Output;
import com.pulumi.aws.s3.BucketV2;
import com.pulumi.aws.s3.BucketCorsConfigurationV2;
import com.pulumi.aws.s3.BucketCorsConfigurationV2Args;
import com.pulumi.aws.s3.inputs.BucketCorsConfigurationV2CorsRuleArgs;
import java.util.List;
import java.util.ArrayList;
import java.util.Map;
import java.io.File;
import java.nio.file.Files;
import java.nio.file.Paths;

public class App {
    public static void main(String[] args) {
        Pulumi.run(App::stack);
    }

    public static void stack(Context ctx) {
        var exampleBucketV2 = new BucketV2("exampleBucketV2");

        var exampleBucketCorsConfigurationV2 = new BucketCorsConfigurationV2("exampleBucketCorsConfigurationV2", BucketCorsConfigurationV2Args.builder()        
            .bucket(exampleBucketV2.id())
            .corsRules(            
                BucketCorsConfigurationV2CorsRuleArgs.builder()
                    .allowedHeaders("*")
                    .allowedMethods(                    
                        "PUT",
                        "POST")
                    .allowedOrigins("https://s3-website-test.domain.example")
                    .exposeHeaders("ETag")
                    .maxAgeSeconds(3000)
                    .build(),
                BucketCorsConfigurationV2CorsRuleArgs.builder()
                    .allowedMethods("GET")
                    .allowedOrigins("*")
                    .build())
            .build());

    }
}
import pulumi
import pulumi_aws as aws

example_bucket_v2 = aws.s3.BucketV2("exampleBucketV2")
example_bucket_cors_configuration_v2 = aws.s3.BucketCorsConfigurationV2("exampleBucketCorsConfigurationV2",
    bucket=example_bucket_v2.id,
    cors_rules=[
        aws.s3.BucketCorsConfigurationV2CorsRuleArgs(
            allowed_headers=["*"],
            allowed_methods=[
                "PUT",
                "POST",
            ],
            allowed_origins=["https://s3-website-test.domain.example"],
            expose_headers=["ETag"],
            max_age_seconds=3000,
        ),
        aws.s3.BucketCorsConfigurationV2CorsRuleArgs(
            allowed_methods=["GET"],
            allowed_origins=["*"],
        ),
    ])
import * as pulumi from "@pulumi/pulumi";
import * as aws from "@pulumi/aws";

const exampleBucketV2 = new aws.s3.BucketV2("exampleBucketV2", {});
const exampleBucketCorsConfigurationV2 = new aws.s3.BucketCorsConfigurationV2("exampleBucketCorsConfigurationV2", {
    bucket: exampleBucketV2.id,
    corsRules: [
        {
            allowedHeaders: ["*"],
            allowedMethods: [
                "PUT",
                "POST",
            ],
            allowedOrigins: ["https://s3-website-test.domain.example"],
            exposeHeaders: ["ETag"],
            maxAgeSeconds: 3000,
        },
        {
            allowedMethods: ["GET"],
            allowedOrigins: ["*"],
        },
    ],
});
resources:
  exampleBucketV2:
    type: aws:s3:BucketV2
  exampleBucketCorsConfigurationV2:
    type: aws:s3:BucketCorsConfigurationV2
    properties:
      bucket: ${exampleBucketV2.id}
      corsRules:
        - allowedHeaders:
            - '*'
          allowedMethods:
            - PUT
            - POST
          allowedOrigins:
            - https://s3-website-test.domain.example
          exposeHeaders:
            - ETag
          maxAgeSeconds: 3000
        - allowedMethods:
            - GET
          allowedOrigins:
            - '*'

Create BucketCorsConfigurationV2 Resource

new BucketCorsConfigurationV2(name: string, args: BucketCorsConfigurationV2Args, opts?: CustomResourceOptions);
@overload
def BucketCorsConfigurationV2(resource_name: str,
                              opts: Optional[ResourceOptions] = None,
                              bucket: Optional[str] = None,
                              cors_rules: Optional[Sequence[BucketCorsConfigurationV2CorsRuleArgs]] = None,
                              expected_bucket_owner: Optional[str] = None)
@overload
def BucketCorsConfigurationV2(resource_name: str,
                              args: BucketCorsConfigurationV2Args,
                              opts: Optional[ResourceOptions] = None)
func NewBucketCorsConfigurationV2(ctx *Context, name string, args BucketCorsConfigurationV2Args, opts ...ResourceOption) (*BucketCorsConfigurationV2, error)
public BucketCorsConfigurationV2(string name, BucketCorsConfigurationV2Args args, CustomResourceOptions? opts = null)
public BucketCorsConfigurationV2(String name, BucketCorsConfigurationV2Args args)
public BucketCorsConfigurationV2(String name, BucketCorsConfigurationV2Args args, CustomResourceOptions options)
type: aws:s3:BucketCorsConfigurationV2
properties: # The arguments to resource properties.
options: # Bag of options to control resource's behavior.

name string
The unique name of the resource.
args BucketCorsConfigurationV2Args
The arguments to resource properties.
opts CustomResourceOptions
Bag of options to control resource's behavior.
resource_name str
The unique name of the resource.
args BucketCorsConfigurationV2Args
The arguments to resource properties.
opts ResourceOptions
Bag of options to control resource's behavior.
ctx Context
Context object for the current deployment.
name string
The unique name of the resource.
args BucketCorsConfigurationV2Args
The arguments to resource properties.
opts ResourceOption
Bag of options to control resource's behavior.
name string
The unique name of the resource.
args BucketCorsConfigurationV2Args
The arguments to resource properties.
opts CustomResourceOptions
Bag of options to control resource's behavior.
name String
The unique name of the resource.
args BucketCorsConfigurationV2Args
The arguments to resource properties.
options CustomResourceOptions
Bag of options to control resource's behavior.

BucketCorsConfigurationV2 Resource Properties

To learn more about resource properties and how to use them, see Inputs and Outputs in the Architecture and Concepts docs.

Inputs

The BucketCorsConfigurationV2 resource accepts the following input properties:

Bucket string

Name of the bucket.

CorsRules List<BucketCorsConfigurationV2CorsRuleArgs>

Set of origins and methods (cross-origin access that you want to allow). See below. You can configure up to 100 rules.

ExpectedBucketOwner string

Account ID of the expected bucket owner.

Bucket string

Name of the bucket.

CorsRules []BucketCorsConfigurationV2CorsRuleArgs

Set of origins and methods (cross-origin access that you want to allow). See below. You can configure up to 100 rules.

ExpectedBucketOwner string

Account ID of the expected bucket owner.

bucket String

Name of the bucket.

corsRules List<BucketCorsConfigurationV2CorsRuleArgs>

Set of origins and methods (cross-origin access that you want to allow). See below. You can configure up to 100 rules.

expectedBucketOwner String

Account ID of the expected bucket owner.

bucket string

Name of the bucket.

corsRules BucketCorsConfigurationV2CorsRuleArgs[]

Set of origins and methods (cross-origin access that you want to allow). See below. You can configure up to 100 rules.

expectedBucketOwner string

Account ID of the expected bucket owner.

bucket str

Name of the bucket.

cors_rules Sequence[BucketCorsConfigurationV2CorsRuleArgs]

Set of origins and methods (cross-origin access that you want to allow). See below. You can configure up to 100 rules.

expected_bucket_owner str

Account ID of the expected bucket owner.

bucket String

Name of the bucket.

corsRules List<Property Map>

Set of origins and methods (cross-origin access that you want to allow). See below. You can configure up to 100 rules.

expectedBucketOwner String

Account ID of the expected bucket owner.

Outputs

All input properties are implicitly available as output properties. Additionally, the BucketCorsConfigurationV2 resource produces the following output properties:

Id string

The provider-assigned unique ID for this managed resource.

Id string

The provider-assigned unique ID for this managed resource.

id String

The provider-assigned unique ID for this managed resource.

id string

The provider-assigned unique ID for this managed resource.

id str

The provider-assigned unique ID for this managed resource.

id String

The provider-assigned unique ID for this managed resource.

Look up Existing BucketCorsConfigurationV2 Resource

Get an existing BucketCorsConfigurationV2 resource’s state with the given name, ID, and optional extra properties used to qualify the lookup.

public static get(name: string, id: Input<ID>, state?: BucketCorsConfigurationV2State, opts?: CustomResourceOptions): BucketCorsConfigurationV2
@staticmethod
def get(resource_name: str,
        id: str,
        opts: Optional[ResourceOptions] = None,
        bucket: Optional[str] = None,
        cors_rules: Optional[Sequence[BucketCorsConfigurationV2CorsRuleArgs]] = None,
        expected_bucket_owner: Optional[str] = None) -> BucketCorsConfigurationV2
func GetBucketCorsConfigurationV2(ctx *Context, name string, id IDInput, state *BucketCorsConfigurationV2State, opts ...ResourceOption) (*BucketCorsConfigurationV2, error)
public static BucketCorsConfigurationV2 Get(string name, Input<string> id, BucketCorsConfigurationV2State? state, CustomResourceOptions? opts = null)
public static BucketCorsConfigurationV2 get(String name, Output<String> id, BucketCorsConfigurationV2State state, CustomResourceOptions options)
Resource lookup is not supported in YAML
name
The unique name of the resulting resource.
id
The unique provider ID of the resource to lookup.
state
Any extra arguments used during the lookup.
opts
A bag of options that control this resource's behavior.
resource_name
The unique name of the resulting resource.
id
The unique provider ID of the resource to lookup.
name
The unique name of the resulting resource.
id
The unique provider ID of the resource to lookup.
state
Any extra arguments used during the lookup.
opts
A bag of options that control this resource's behavior.
name
The unique name of the resulting resource.
id
The unique provider ID of the resource to lookup.
state
Any extra arguments used during the lookup.
opts
A bag of options that control this resource's behavior.
name
The unique name of the resulting resource.
id
The unique provider ID of the resource to lookup.
state
Any extra arguments used during the lookup.
opts
A bag of options that control this resource's behavior.
The following state arguments are supported:
Bucket string

Name of the bucket.

CorsRules List<BucketCorsConfigurationV2CorsRuleArgs>

Set of origins and methods (cross-origin access that you want to allow). See below. You can configure up to 100 rules.

ExpectedBucketOwner string

Account ID of the expected bucket owner.

Bucket string

Name of the bucket.

CorsRules []BucketCorsConfigurationV2CorsRuleArgs

Set of origins and methods (cross-origin access that you want to allow). See below. You can configure up to 100 rules.

ExpectedBucketOwner string

Account ID of the expected bucket owner.

bucket String

Name of the bucket.

corsRules List<BucketCorsConfigurationV2CorsRuleArgs>

Set of origins and methods (cross-origin access that you want to allow). See below. You can configure up to 100 rules.

expectedBucketOwner String

Account ID of the expected bucket owner.

bucket string

Name of the bucket.

corsRules BucketCorsConfigurationV2CorsRuleArgs[]

Set of origins and methods (cross-origin access that you want to allow). See below. You can configure up to 100 rules.

expectedBucketOwner string

Account ID of the expected bucket owner.

bucket str

Name of the bucket.

cors_rules Sequence[BucketCorsConfigurationV2CorsRuleArgs]

Set of origins and methods (cross-origin access that you want to allow). See below. You can configure up to 100 rules.

expected_bucket_owner str

Account ID of the expected bucket owner.

bucket String

Name of the bucket.

corsRules List<Property Map>

Set of origins and methods (cross-origin access that you want to allow). See below. You can configure up to 100 rules.

expectedBucketOwner String

Account ID of the expected bucket owner.

Supporting Types

BucketCorsConfigurationV2CorsRule

AllowedMethods List<string>

Set of HTTP methods that you allow the origin to execute. Valid values are GET, PUT, HEAD, POST, and DELETE.

AllowedOrigins List<string>

Set of origins you want customers to be able to access the bucket from.

AllowedHeaders List<string>

Set of Headers that are specified in the Access-Control-Request-Headers header.

ExposeHeaders List<string>

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

Id string

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

MaxAgeSeconds int

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

AllowedMethods []string

Set of HTTP methods that you allow the origin to execute. Valid values are GET, PUT, HEAD, POST, and DELETE.

AllowedOrigins []string

Set of origins you want customers to be able to access the bucket from.

AllowedHeaders []string

Set of Headers that are specified in the Access-Control-Request-Headers header.

ExposeHeaders []string

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

Id string

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

MaxAgeSeconds int

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

allowedMethods List<String>

Set of HTTP methods that you allow the origin to execute. Valid values are GET, PUT, HEAD, POST, and DELETE.

allowedOrigins List<String>

Set of origins you want customers to be able to access the bucket from.

allowedHeaders List<String>

Set of Headers that are specified in the Access-Control-Request-Headers header.

exposeHeaders List<String>

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

id String

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

maxAgeSeconds Integer

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

allowedMethods string[]

Set of HTTP methods that you allow the origin to execute. Valid values are GET, PUT, HEAD, POST, and DELETE.

allowedOrigins string[]

Set of origins you want customers to be able to access the bucket from.

allowedHeaders string[]

Set of Headers that are specified in the Access-Control-Request-Headers header.

exposeHeaders string[]

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

id string

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

maxAgeSeconds number

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

allowed_methods Sequence[str]

Set of HTTP methods that you allow the origin to execute. Valid values are GET, PUT, HEAD, POST, and DELETE.

allowed_origins Sequence[str]

Set of origins you want customers to be able to access the bucket from.

allowed_headers Sequence[str]

Set of Headers that are specified in the Access-Control-Request-Headers header.

expose_headers Sequence[str]

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

id str

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

max_age_seconds int

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

allowedMethods List<String>

Set of HTTP methods that you allow the origin to execute. Valid values are GET, PUT, HEAD, POST, and DELETE.

allowedOrigins List<String>

Set of origins you want customers to be able to access the bucket from.

allowedHeaders List<String>

Set of Headers that are specified in the Access-Control-Request-Headers header.

exposeHeaders List<String>

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

id String

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

maxAgeSeconds Number

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

Import

S3 bucket CORS configuration can be imported in one of two ways. If the owner (account ID) of the source bucket is the same account used to configure the AWS Provider, the S3 bucket CORS configuration resource should be imported using the bucket e.g.,

 $ pulumi import aws:s3/bucketCorsConfigurationV2:BucketCorsConfigurationV2 example bucket-name

If the owner (account ID) of the source bucket differs from the account used to configure the AWS Provider, the S3 bucket CORS configuration resource should be imported using the bucket and expected_bucket_owner separated by a comma (,) e.g.,

 $ pulumi import aws:s3/bucketCorsConfigurationV2:BucketCorsConfigurationV2 example bucket-name,123456789012

Package Details

Repository
AWS Classic pulumi/pulumi-aws
License
Apache-2.0
Notes

This Pulumi package is based on the aws Terraform Provider.