BucketV2 class
Provides a S3 bucket resource.
> This resource provides functionality for managing S3 general purpose buckets in an AWS Partition. To manage Amazon S3 Express directory buckets, use the aws.s3.DirectoryBucket resource. To manage S3 on Outposts, use the aws.s3control.Bucket resource.
> Object Lock can be enabled by using the objectLockEnabled attribute or by using the aws.s3.BucketObjectLockConfiguration resource. Please note, that by using the resource, Object Lock can be enabled/disabled without destroying and recreating the bucket.
> To support ABAC (Attribute Based Access Control) in general purpose buckets, this resource will now attempt to send tags in the create request and use the S3 Control tagging APIs TagResource, UntagResource, and ListTagsForResource for read and update operations. The calling principal must have the corresponding s3:TagResource, s3:UntagResource, and s3:ListTagsForResource IAM permissions. If the principal lacks the appropriate permissions, the provider will fall back to tagging after creation and using the S3 tagging APIs PutBucketTagging, DeleteBucketTagging, and GetBucketTagging instead. With ABAC enabled, tag modifications may fail with the fall back behavior. See the AWS documentation for additional details on enabling ABAC in general purpose buckets.
Example Usage
Private Bucket With Tags
import * as pulumi from "@pulumi/pulumi";
import * as aws from "@pulumi/aws";
const example = new aws.s3.Bucket("example", {
bucket: "my-tf-test-bucket",
tags: {
Name: "My bucket",
Environment: "Dev",
},
});
import pulumi
import pulumi_aws as aws
example = aws.s3.Bucket("example",
bucket="my-tf-test-bucket",
tags={
"Name": "My bucket",
"Environment": "Dev",
})
using System.Collections.Generic;
using System.Linq;
using Pulumi;
using Aws = Pulumi.Aws;
return await Deployment.RunAsync(() =>
{
var example = new Aws.S3.Bucket("example", new()
{
BucketName = "my-tf-test-bucket",
Tags =
{
{ "Name", "My bucket" },
{ "Environment", "Dev" },
},
});
});
package main
import (
"github.com/pulumi/pulumi-aws/sdk/v7/go/aws/s3"
"github.com/pulumi/pulumi/sdk/v3/go/pulumi"
)
func main() {
pulumi.Run(func(ctx *pulumi.Context) error {
_, err := s3.NewBucket(ctx, "example", &s3.BucketArgs{
Bucket: pulumi.String("my-tf-test-bucket"),
Tags: pulumi.StringMap{
"Name": pulumi.String("My bucket"),
"Environment": pulumi.String("Dev"),
},
})
if err != nil {
return err
}
return nil
})
}
pulumi {
required_providers {
aws = {
source = "pulumi/aws"
}
}
}
resource "aws_s3_bucket" "example" {
bucket = "my-tf-test-bucket"
tags = {
"Name" = "My bucket"
"Environment" = "Dev"
}
}
package generated_program;
import com.pulumi.Context;
import com.pulumi.Pulumi;
import com.pulumi.core.Output;
import com.pulumi.aws.s3.Bucket;
import com.pulumi.aws.s3.BucketArgs;
import java.util.ArrayList;
import java.util.Arrays;
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 example = new Bucket("example", BucketArgs.builder()
.bucket("my-tf-test-bucket")
.tags(Map.ofEntries(
Map.entry("Name", "My bucket"),
Map.entry("Environment", "Dev")
))
.build());
}
}
resources:
example:
type: aws:s3:Bucket
properties:
bucket: my-tf-test-bucket
tags:
Name: My bucket
Environment: Dev
Bucket In Account-Regional Namespace
import * as pulumi from "@pulumi/pulumi";
import * as aws from "@pulumi/aws";
import * as std from "@pulumi/std";
const current = aws.getCallerIdentity({});
const currentGetRegion = aws.getRegion({});
const example = new aws.s3.Bucket("example", {
bucket: std.format({
input: "my-tf-test-bucket-%s-%s-an",
args: [
current.then(current => current.accountId),
currentGetRegion.then(currentGetRegion => currentGetRegion.region),
],
}).then(invoke => invoke.result),
bucketNamespace: "account-regional",
});
import pulumi
import pulumi_aws as aws
import pulumi_std as std
current = aws.get_caller_identity()
current_get_region = aws.get_region()
example = aws.s3.Bucket("example",
bucket=std.format(input="my-tf-test-bucket-%s-%s-an",
args=[
current.account_id,
current_get_region.region,
]).result,
bucket_namespace="account-regional")
using System.Collections.Generic;
using System.Linq;
using Pulumi;
using Aws = Pulumi.Aws;
using Std = Pulumi.Std;
return await Deployment.RunAsync(() =>
{
var current = Aws.GetCallerIdentity.Invoke();
var currentGetRegion = Aws.GetRegion.Invoke();
var example = new Aws.S3.Bucket("example", new()
{
BucketName = Std.Format.Invoke(new()
{
Input = "my-tf-test-bucket-%s-%s-an",
Args = new[]
{
current.Apply(getCallerIdentityResult => getCallerIdentityResult.AccountId),
currentGetRegion.Apply(getRegionResult => getRegionResult.Region),
},
}).Apply(invoke => invoke.Result),
BucketNamespace = "account-regional",
});
});
package main
import (
"github.com/pulumi/pulumi-aws/sdk/v7/go/aws"
"github.com/pulumi/pulumi-aws/sdk/v7/go/aws/s3"
"github.com/pulumi/pulumi-std/sdk/go/std"
"github.com/pulumi/pulumi/sdk/v3/go/pulumi"
)
func main() {
pulumi.Run(func(ctx *pulumi.Context) error {
current, err := aws.GetCallerIdentity(ctx, &aws.GetCallerIdentityArgs{}, nil)
if err != nil {
return err
}
currentGetRegion, err := aws.GetRegion(ctx, &aws.GetRegionArgs{}, nil)
if err != nil {
return err
}
invokeFormat, err := std.Format(ctx, &std.FormatArgs{
Input: "my-tf-test-bucket-%s-%s-an",
Args: []*string{
current.AccountId,
currentGetRegion.Region,
},
}, nil)
if err != nil {
return err
}
_, err = s3.NewBucket(ctx, "example", &s3.BucketArgs{
Bucket: pulumi.String(invokeFormat.Result),
BucketNamespace: pulumi.String("account-regional"),
})
if err != nil {
return err
}
return nil
})
}
pulumi {
required_providers {
aws = {
source = "pulumi/aws"
}
std = {
source = "pulumi/std"
}
}
}
data "std_format" "invoke_0" {
input = "my-tf-test-bucket-%s-%s-an"
args = [data.aws_getcalleridentity.current.account_id, data.aws_getregion.currentGetRegion.region]
}
data "aws_getcalleridentity" "current" {
}
data "aws_getregion" "currentGetRegion" {
}
resource "aws_s3_bucket" "example" {
bucket = data.std_format.invoke_0.result
bucket_namespace = "account-regional"
}
package generated_program;
import com.pulumi.Context;
import com.pulumi.Pulumi;
import com.pulumi.core.Output;
import com.pulumi.aws.AwsFunctions;
import com.pulumi.aws.inputs.GetCallerIdentityArgs;
import com.pulumi.aws.inputs.GetRegionArgs;
import com.pulumi.aws.s3.Bucket;
import com.pulumi.aws.s3.BucketArgs;
import com.pulumi.std.StdFunctions;
import com.pulumi.std.inputs.FormatArgs;
import java.util.ArrayList;
import java.util.Arrays;
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) {
final var current = AwsFunctions.getCallerIdentity(GetCallerIdentityArgs.builder()
.build());
final var currentGetRegion = AwsFunctions.getRegion(GetRegionArgs.builder()
.build());
var example = new Bucket("example", BucketArgs.builder()
.bucket(StdFunctions.format(FormatArgs.builder()
.input("my-tf-test-bucket-%s-%s-an")
.args(
current.accountId(),
currentGetRegion.region())
.build()).result())
.bucketNamespace("account-regional")
.build());
}
}
resources:
example:
type: aws:s3:Bucket
properties:
bucket:
fn::invoke:
function: std:format
arguments:
input: my-tf-test-bucket-%s-%s-an
args:
- ${current.accountId}
- ${currentGetRegion.region}
return: result
bucketNamespace: account-regional
variables:
current:
fn::invoke:
function: aws:getCallerIdentity
arguments: {}
currentGetRegion:
fn::invoke:
function: aws:getRegion
arguments: {}
Import
Identity Schema
Required
bucket(String) Name of the S3 bucket.
Optional
accountId(String) AWS Account where this resource is managed.region(String) Region where this resource is managed.
Using pulumi import, import S3 bucket using the bucket. For example:
$ pulumi import aws:s3/bucketV2:BucketV2 example bucket-name
Constructors
- BucketV2(String name, {BucketV2Args? args, CustomResourceOptions? options})
-
Creates a new BucketV2.
nameThe Pulumi resource name.argsArguments used to configure this BucketV2. The set of arguments for BucketV2.optionsResource options controlling this resource's behavior. - BucketV2.reference(String urn)
- Creates a typed reference to an existing BucketV2 resource.
Properties
-
accelerationStatus
↔ Output<
String> -
Sets the accelerate configuration of an existing bucket. Can be
EnabledorSuspended. Cannot be used incn-north-1orus-gov-west-1. This provider will only perform drift detection if a configuration value is provided. Use the resourceaws.s3.BucketAccelerateConfigurationinstead.latefinal -
acl
↔ Output<
String> -
Canned ACL to apply. Valid values are
private,public-read,public-read-write,aws-exec-read,authenticated-read, andlog-delivery-write. Defaults toprivate. Conflicts withgrant. The provider will only perform drift detection if a configuration value is provided. Use the resourceaws.s3.BucketAclinstead.latefinal -
arn
↔ Output<
String> -
ARN of the bucket. Will be of format
arn:aws:s3:::bucketname.latefinal -
bucket
↔ Output<
String> -
Name of the bucket. If omitted, the provider will assign a random, unique name. Must be lowercase and less than or equal to 63 characters in length. A full list of bucket naming rules may be found here. The name must not be in the format
[bucketName]--[azid]--x-s3. Use theaws.s3.DirectoryBucketresource to manage S3 Express buckets.latefinal -
bucketDomainName
↔ Output<
String> -
Bucket domain name. Will be of format
bucketname.s3.amazonaws.com.latefinal -
bucketNamespace
↔ Output<
String> -
Namespace for the bucket. Determines bucket naming scope. Valid values:
account-regional,global. Defaults toglobal(AWS).latefinal -
bucketPrefix
↔ Output<
String> -
Creates a unique bucket name beginning with the specified prefix. Conflicts with
bucket. Must be lowercase and less than or equal to 37 characters in length. A full list of bucket naming rules may be found here.latefinal -
bucketRegion
↔ Output<
String> -
AWS region this bucket resides in.
latefinal
-
bucketRegionalDomainName
↔ Output<
String> -
Bucket region-specific domain name. The bucket domain name including the region name. Please refer to the S3 endpoints reference for format. Note: AWS CloudFront allows specifying an S3 region-specific endpoint when creating an S3 origin. This will prevent redirect issues from CloudFront to the S3 Origin URL. For more information, see the Virtual Hosted-Style Requests for Other Regions section in the AWS S3 User Guide.
latefinal
-
childResources
→ Set<
Resource> -
finalinherited
-
completionSources
↔ Map<
String, IOutputCompletionSource> -
latefinalinherited
-
corsRules
↔ Output<
List< BucketV2CorsRule> > -
Rule of Cross-Origin Resource Sharing. See
corsRuleBlock below for details. The provider will only perform drift detection if a configuration value is provided. Use the resourceaws.s3.BucketCorsConfigurationinstead.latefinal -
forceDestroy
↔ Output<
bool?> -
Boolean that indicates all objects (including any locked objects) should be deleted from the bucket when the bucket is destroyed so that the bucket can be destroyed without error. These objects are not recoverable. This only deletes objects when the bucket is destroyed, not when setting this parameter to
true. Once this parameter is set totrue, there must be a successfulpulumi uprun before a destroy is required to update this value in the resource state. Without a successfulpulumi upafter this parameter is set, this flag will have no effect. If setting this field in the same operation that would require replacing the bucket or destroying the bucket, this flag will not work. Additionally when importing a bucket, a successfulpulumi upis required to set this value in state before it will take effect on a destroy operation.latefinal -
grants
↔ Output<
List< BucketV2Grant> > -
ACL policy grant. See
grantBlock below for details. Conflicts withacl. The provider will only perform drift detection if a configuration value is provided. Use the resourceaws.s3.BucketAclinstead.latefinal - hashCode → int
-
The hash code for this object.
no setterinherited
-
hostedZoneId
↔ Output<
String> -
Route 53 Hosted Zone ID for this bucket's region.
latefinal
-
id
↔ Output<
String> -
getter/setter pairinherited
- isCustom → bool
-
Returns whether this resource is provider-managed.
no setterinherited
- isProtected → bool
-
Returns whether this resource is protected from deletion.
no setterinherited
- isRemote → bool
-
Whether this resource is registered as remote.
no setterinherited
- isResourceReference → bool
-
Whether this instance represents a resource value returned over RPC.
finalinherited
-
lifecycleRules
↔ Output<
List< BucketV2LifecycleRule> > -
Configuration of object lifecycle management. See
lifecycleRuleBlock below for details. The provider will only perform drift detection if a configuration value is provided. Use the resourceaws.s3.BucketLifecycleConfigurationinstead.latefinal -
loggings
↔ Output<
List< BucketV2Logging> > -
Configuration of S3 bucket logging parameters. See
loggingBlock below for details. The provider will only perform drift detection if a configuration value is provided. Use the resourceaws.s3.BucketLogginginstead.latefinal -
objectLockConfiguration
↔ Output<
BucketV2ObjectLockConfiguration> -
Configuration of S3 object locking. See
objectLockConfigurationBlock below for details. The provider will only perform drift detection if a configuration value is provided. Use theobjectLockEnabledparameter and the resourceaws.s3.BucketObjectLockConfigurationinstead.latefinal -
objectLockEnabled
↔ Output<
bool> -
Whether this bucket has an Object Lock configuration enabled. Valid values are
trueorfalse. This argument is not supported in all regions or partitions.latefinal -
policy
↔ Output<
String> -
Valid bucket policy JSON document. Note that if the policy document is not specific enough (but still valid), this provider may view the policy as constantly changing. In this case, please make sure you use the verbose/specific version of the policy. For more information about building AWS IAM policy documents with this provider, see the AWS IAM Policy Document Guide. The provider will only perform drift detection if a configuration value is provided. Use the resource
aws.s3.BucketPolicyinstead.latefinal -
region
↔ Output<
String> -
Region where this resource will be managed. Defaults to the Region set in the provider configuration.
latefinal
-
replicationConfigurations
↔ Output<
List< BucketV2ReplicationConfiguration> > -
Configuration of replication configuration. See
replicationConfigurationBlock below for details. The provider will only perform drift detection if a configuration value is provided. Use the resourceaws.s3.BucketReplicationConfiginstead.latefinal -
requestPayer
↔ Output<
String> -
Who should bear the cost of Amazon S3 data transfer. Can be either
BucketOwnerorRequester. By default, the owner of the S3 bucket would incur the costs of any data transfer. See Requester Pays Buckets developer guide for more information. The provider will only perform drift detection if a configuration value is provided. Use the resourceaws.s3.BucketRequestPaymentConfigurationinstead.latefinal -
resourceTransforms
→ List<
ResourceTransform> -
Inherited/explicit async transforms.
no setterinherited
- runtimeType → Type
-
A representation of the runtime type of the object.
no setterinherited
-
serverSideEncryptionConfigurations
↔ Output<
List< BucketV2ServerSideEncryptionConfiguration> > -
Configuration of server-side encryption configuration. See
serverSideEncryptionConfigurationBlock below for details. The provider will only perform drift detection if a configuration value is provided. Use the resourceaws.s3.BucketServerSideEncryptionConfigurationinstead.latefinal -
Map of tags to assign to the bucket. If configured with a provider
defaultTagsconfiguration block present, tags with matching keys will overwrite those defined at the provider-level.latefinal -
Map of tags assigned to the resource, including those inherited from the provider
defaultTagsconfiguration block.latefinal -
transformations
→ List<
ResourceTransformation> -
Inherited/explicit legacy transformations.
no setterinherited
-
urn
↔ Output<
String> -
latefinalinherited
-
versionings
↔ Output<
List< BucketV2Versioning> > -
Configuration of the S3 bucket versioning state. See
versioningBlock below for details. The provider will only perform drift detection if a configuration value is provided. Use the resourceaws.s3.BucketVersioninginstead.latefinal -
websiteDomain
↔ Output<
String> -
(Deprecated) Domain of the website endpoint, if the bucket is configured with a website. If not, this will be an empty string. This is used to create Route 53 alias records. Use the resource
aws.s3.BucketWebsiteConfigurationinstead.latefinal -
websiteEndpoint
↔ Output<
String> -
(Deprecated) Website endpoint, if the bucket is configured with a website. If not, this will be an empty string. Use the resource
aws.s3.BucketWebsiteConfigurationinstead.latefinal -
websites
↔ Output<
List< BucketV2Website> > -
Configuration of the S3 bucket website. See
websiteBlock below for details. The provider will only perform drift detection if a configuration value is provided. Use the resourceaws.s3.BucketWebsiteConfigurationinstead.latefinal
Methods
-
failId(
Object error) → void -
Completes this resource ID with an error when registration fails.
inherited
-
failOutputs(
Object error) → void -
Completes all output properties with
error.inherited -
failUrn(
Object error) → void -
Completes this resource URN with an error when registration fails.
inherited
-
getProvider(
String moduleMember) → ProviderResource? -
Returns provider for
moduleMember's package, if configured.inherited -
getResourceName(
) → String -
Returns this resource's logical name.
inherited
-
getResourceType(
) → String -
Returns this resource's Pulumi type token.
inherited
-
noSuchMethod(
Invocation invocation) → dynamic -
Invoked when a nonexistent method or property is accessed.
inherited
-
registerOutput<
T> (String propertyName, {Object? decoder(Object?)?, bool isSecret = false}) → Output< T> -
Registers a dynamic output property for this resource.
inherited
-
resolveId(
String? value, {required bool isKnown}) → void -
Resolves the provider-assigned ID for this resource.
inherited
-
resolveOutputs(
Struct outputs) → void -
Resolves all output properties from a monitor response payload.
inherited
-
resolveUrn(
String value) → void -
Resolves this resource's URN once assigned by the engine.
inherited
-
serializeProperties(
Map< String, dynamic> properties) → Future<Struct> -
Serializes resource properties for RPC transmission.
inherited
-
toString(
) → String -
A string representation of this object.
inherited
Operators
-
operator ==(
Object other) → bool -
The equality operator.
inherited