BucketObjectv2 class
Provides an S3 object resource.
Example Usage
Uploading a file to a bucket
import * as pulumi from "@pulumi/pulumi";
import * as aws from "@pulumi/aws";
import * as std from "@pulumi/std";
const object = new aws.s3.BucketObjectv2("object", {
bucket: "your_bucket_name",
key: "new_object_key",
source: new pulumi.asset.FileAsset("path/to/file"),
etag: std.filemd5({
input: "path/to/file",
}).then(invoke => invoke.result),
});
import pulumi
import pulumi_aws as aws
import pulumi_std as std
object = aws.s3.BucketObjectv2("object",
bucket="your_bucket_name",
key="new_object_key",
source=pulumi.FileAsset("path/to/file"),
etag=std.filemd5(input="path/to/file").result)
using System.Collections.Generic;
using System.Linq;
using Pulumi;
using Aws = Pulumi.Aws;
using Std = Pulumi.Std;
return await Deployment.RunAsync(() =>
{
var @object = new Aws.S3.BucketObjectv2("object", new()
{
Bucket = "your_bucket_name",
Key = "new_object_key",
Source = new FileAsset("path/to/file"),
Etag = Std.Filemd5.Invoke(new()
{
Input = "path/to/file",
}).Apply(invoke => invoke.Result),
});
});
package main
import (
"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 {
invokeFilemd5, err := std.Filemd5(ctx, &std.Filemd5Args{
Input: "path/to/file",
}, nil)
if err != nil {
return err
}
_, err = s3.NewBucketObjectv2(ctx, "object", &s3.BucketObjectv2Args{
Bucket: pulumi.Any("your_bucket_name"),
Key: pulumi.String("new_object_key"),
Source: pulumi.NewFileAsset("path/to/file"),
Etag: pulumi.String(invokeFilemd5.Result),
})
if err != nil {
return err
}
return nil
})
}
pulumi {
required_providers {
aws = {
source = "pulumi/aws"
}
std = {
source = "pulumi/std"
}
}
}
resource "aws_s3_bucketobjectv2" "object" {
bucket = "your_bucket_name"
key = "new_object_key"
source = fileAsset("path/to/file")
etag = filemd5("path/to/file")
}
package generated_program;
import com.pulumi.Context;
import com.pulumi.Pulumi;
import com.pulumi.core.Output;
import com.pulumi.aws.s3.BucketObjectv2;
import com.pulumi.aws.s3.BucketObjectv2Args;
import com.pulumi.std.StdFunctions;
import com.pulumi.std.inputs.Filemd5Args;
import com.pulumi.asset.FileAsset;
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 object = new BucketObjectv2("object", BucketObjectv2Args.builder()
.bucket("your_bucket_name")
.key("new_object_key")
.source(new FileAsset("path/to/file"))
.etag(StdFunctions.filemd5(Filemd5Args.builder()
.input("path/to/file")
.build()).result())
.build());
}
}
resources:
object:
type: aws:s3:BucketObjectv2
properties:
bucket: your_bucket_name
key: new_object_key
source:
fn::fileAsset: path/to/file
etag:
fn::invoke:
function: std:filemd5
arguments:
input: path/to/file
return: result
Encrypting with KMS Key
import * as pulumi from "@pulumi/pulumi";
import * as aws from "@pulumi/aws";
const examplekms = new aws.kms.Key("examplekms", {
description: "KMS key 1",
deletionWindowInDays: 7,
});
const examplebucket = new aws.s3.Bucket("examplebucket", {bucket: "examplebuckettftest"});
const example = new aws.s3.BucketAcl("example", {
bucket: examplebucket.id,
acl: "private",
});
const exampleBucketObjectv2 = new aws.s3.BucketObjectv2("example", {
key: "someobject",
bucket: examplebucket.id,
source: new pulumi.asset.FileAsset("index.html"),
kmsKeyId: examplekms.arn,
});
import pulumi
import pulumi_aws as aws
examplekms = aws.kms.Key("examplekms",
description="KMS key 1",
deletion_window_in_days=7)
examplebucket = aws.s3.Bucket("examplebucket", bucket="examplebuckettftest")
example = aws.s3.BucketAcl("example",
bucket=examplebucket.id,
acl="private")
example_bucket_objectv2 = aws.s3.BucketObjectv2("example",
key="someobject",
bucket=examplebucket.id,
source=pulumi.FileAsset("index.html"),
kms_key_id=examplekms.arn)
using System.Collections.Generic;
using System.Linq;
using Pulumi;
using Aws = Pulumi.Aws;
return await Deployment.RunAsync(() =>
{
var examplekms = new Aws.Kms.Key("examplekms", new()
{
Description = "KMS key 1",
DeletionWindowInDays = 7,
});
var examplebucket = new Aws.S3.Bucket("examplebucket", new()
{
BucketName = "examplebuckettftest",
});
var example = new Aws.S3.BucketAcl("example", new()
{
Bucket = examplebucket.Id,
Acl = "private",
});
var exampleBucketObjectv2 = new Aws.S3.BucketObjectv2("example", new()
{
Key = "someobject",
Bucket = examplebucket.Id,
Source = new FileAsset("index.html"),
KmsKeyId = examplekms.Arn,
});
});
package main
import (
"github.com/pulumi/pulumi-aws/sdk/v7/go/aws/kms"
"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 {
examplekms, err := kms.NewKey(ctx, "examplekms", &kms.KeyArgs{
Description: pulumi.String("KMS key 1"),
DeletionWindowInDays: pulumi.Int(7),
})
if err != nil {
return err
}
examplebucket, err := s3.NewBucket(ctx, "examplebucket", &s3.BucketArgs{
Bucket: pulumi.String("examplebuckettftest"),
})
if err != nil {
return err
}
_, err = s3.NewBucketAcl(ctx, "example", &s3.BucketAclArgs{
Bucket: examplebucket.ID().ToIDOutput().ToStringOutput(),
Acl: pulumi.String("private"),
})
if err != nil {
return err
}
_, err = s3.NewBucketObjectv2(ctx, "example", &s3.BucketObjectv2Args{
Key: pulumi.String("someobject"),
Bucket: examplebucket.ID().ToIDOutput().ToStringOutput(),
Source: pulumi.NewFileAsset("index.html"),
KmsKeyId: examplekms.Arn,
})
if err != nil {
return err
}
return nil
})
}
pulumi {
required_providers {
aws = {
source = "pulumi/aws"
}
}
}
resource "aws_kms_key" "examplekms" {
description = "KMS key 1"
deletion_window_in_days = 7
}
resource "aws_s3_bucket" "examplebucket" {
bucket = "examplebuckettftest"
}
resource "aws_s3_bucketacl" "example" {
bucket = aws_s3_bucket.examplebucket.id
acl = "private"
}
resource "aws_s3_bucketobjectv2" "example" {
key = "someobject"
bucket = aws_s3_bucket.examplebucket.id
source = fileAsset("index.html")
kms_key_id = aws_kms_key.examplekms.arn
}
package generated_program;
import com.pulumi.Context;
import com.pulumi.Pulumi;
import com.pulumi.core.Output;
import com.pulumi.aws.kms.Key;
import com.pulumi.aws.kms.KeyArgs;
import com.pulumi.aws.s3.Bucket;
import com.pulumi.aws.s3.BucketArgs;
import com.pulumi.aws.s3.BucketAcl;
import com.pulumi.aws.s3.BucketAclArgs;
import com.pulumi.aws.s3.BucketObjectv2;
import com.pulumi.aws.s3.BucketObjectv2Args;
import com.pulumi.asset.FileAsset;
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 examplekms = new Key("examplekms", KeyArgs.builder()
.description("KMS key 1")
.deletionWindowInDays(7)
.build());
var examplebucket = new Bucket("examplebucket", BucketArgs.builder()
.bucket("examplebuckettftest")
.build());
var example = new BucketAcl("example", BucketAclArgs.builder()
.bucket(examplebucket.id())
.acl("private")
.build());
var exampleBucketObjectv2 = new BucketObjectv2("exampleBucketObjectv2", BucketObjectv2Args.builder()
.key("someobject")
.bucket(examplebucket.id())
.source(new FileAsset("index.html"))
.kmsKeyId(examplekms.arn())
.build());
}
}
resources:
examplekms:
type: aws:kms:Key
properties:
description: KMS key 1
deletionWindowInDays: 7
examplebucket:
type: aws:s3:Bucket
properties:
bucket: examplebuckettftest
example:
type: aws:s3:BucketAcl
properties:
bucket: ${examplebucket.id}
acl: private
exampleBucketObjectv2:
type: aws:s3:BucketObjectv2
name: example
properties:
key: someobject
bucket: ${examplebucket.id}
source:
fn::fileAsset: index.html
kmsKeyId: ${examplekms.arn}
Server Side Encryption with S3 Default Master Key
import * as pulumi from "@pulumi/pulumi";
import * as aws from "@pulumi/aws";
const examplebucket = new aws.s3.Bucket("examplebucket", {bucket: "examplebuckettftest"});
const example = new aws.s3.BucketAcl("example", {
bucket: examplebucket.id,
acl: "private",
});
const exampleBucketObjectv2 = new aws.s3.BucketObjectv2("example", {
key: "someobject",
bucket: examplebucket.id,
source: new pulumi.asset.FileAsset("index.html"),
serverSideEncryption: "aws:kms",
});
import pulumi
import pulumi_aws as aws
examplebucket = aws.s3.Bucket("examplebucket", bucket="examplebuckettftest")
example = aws.s3.BucketAcl("example",
bucket=examplebucket.id,
acl="private")
example_bucket_objectv2 = aws.s3.BucketObjectv2("example",
key="someobject",
bucket=examplebucket.id,
source=pulumi.FileAsset("index.html"),
server_side_encryption="aws:kms")
using System.Collections.Generic;
using System.Linq;
using Pulumi;
using Aws = Pulumi.Aws;
return await Deployment.RunAsync(() =>
{
var examplebucket = new Aws.S3.Bucket("examplebucket", new()
{
BucketName = "examplebuckettftest",
});
var example = new Aws.S3.BucketAcl("example", new()
{
Bucket = examplebucket.Id,
Acl = "private",
});
var exampleBucketObjectv2 = new Aws.S3.BucketObjectv2("example", new()
{
Key = "someobject",
Bucket = examplebucket.Id,
Source = new FileAsset("index.html"),
ServerSideEncryption = "aws:kms",
});
});
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 {
examplebucket, err := s3.NewBucket(ctx, "examplebucket", &s3.BucketArgs{
Bucket: pulumi.String("examplebuckettftest"),
})
if err != nil {
return err
}
_, err = s3.NewBucketAcl(ctx, "example", &s3.BucketAclArgs{
Bucket: examplebucket.ID().ToIDOutput().ToStringOutput(),
Acl: pulumi.String("private"),
})
if err != nil {
return err
}
_, err = s3.NewBucketObjectv2(ctx, "example", &s3.BucketObjectv2Args{
Key: pulumi.String("someobject"),
Bucket: examplebucket.ID().ToIDOutput().ToStringOutput(),
Source: pulumi.NewFileAsset("index.html"),
ServerSideEncryption: pulumi.String("aws:kms"),
})
if err != nil {
return err
}
return nil
})
}
pulumi {
required_providers {
aws = {
source = "pulumi/aws"
}
}
}
resource "aws_s3_bucket" "examplebucket" {
bucket = "examplebuckettftest"
}
resource "aws_s3_bucketacl" "example" {
bucket = aws_s3_bucket.examplebucket.id
acl = "private"
}
resource "aws_s3_bucketobjectv2" "example" {
key = "someobject"
bucket = aws_s3_bucket.examplebucket.id
source = fileAsset("index.html")
server_side_encryption = "aws:kms"
}
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 com.pulumi.aws.s3.BucketAcl;
import com.pulumi.aws.s3.BucketAclArgs;
import com.pulumi.aws.s3.BucketObjectv2;
import com.pulumi.aws.s3.BucketObjectv2Args;
import com.pulumi.asset.FileAsset;
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 examplebucket = new Bucket("examplebucket", BucketArgs.builder()
.bucket("examplebuckettftest")
.build());
var example = new BucketAcl("example", BucketAclArgs.builder()
.bucket(examplebucket.id())
.acl("private")
.build());
var exampleBucketObjectv2 = new BucketObjectv2("exampleBucketObjectv2", BucketObjectv2Args.builder()
.key("someobject")
.bucket(examplebucket.id())
.source(new FileAsset("index.html"))
.serverSideEncryption("aws:kms")
.build());
}
}
resources:
examplebucket:
type: aws:s3:Bucket
properties:
bucket: examplebuckettftest
example:
type: aws:s3:BucketAcl
properties:
bucket: ${examplebucket.id}
acl: private
exampleBucketObjectv2:
type: aws:s3:BucketObjectv2
name: example
properties:
key: someobject
bucket: ${examplebucket.id}
source:
fn::fileAsset: index.html
serverSideEncryption: aws:kms
Server Side Encryption with AWS-Managed Key
import * as pulumi from "@pulumi/pulumi";
import * as aws from "@pulumi/aws";
const examplebucket = new aws.s3.Bucket("examplebucket", {bucket: "examplebuckettftest"});
const example = new aws.s3.BucketAcl("example", {
bucket: examplebucket.id,
acl: "private",
});
const exampleBucketObjectv2 = new aws.s3.BucketObjectv2("example", {
key: "someobject",
bucket: examplebucket.id,
source: new pulumi.asset.FileAsset("index.html"),
serverSideEncryption: "AES256",
});
import pulumi
import pulumi_aws as aws
examplebucket = aws.s3.Bucket("examplebucket", bucket="examplebuckettftest")
example = aws.s3.BucketAcl("example",
bucket=examplebucket.id,
acl="private")
example_bucket_objectv2 = aws.s3.BucketObjectv2("example",
key="someobject",
bucket=examplebucket.id,
source=pulumi.FileAsset("index.html"),
server_side_encryption="AES256")
using System.Collections.Generic;
using System.Linq;
using Pulumi;
using Aws = Pulumi.Aws;
return await Deployment.RunAsync(() =>
{
var examplebucket = new Aws.S3.Bucket("examplebucket", new()
{
BucketName = "examplebuckettftest",
});
var example = new Aws.S3.BucketAcl("example", new()
{
Bucket = examplebucket.Id,
Acl = "private",
});
var exampleBucketObjectv2 = new Aws.S3.BucketObjectv2("example", new()
{
Key = "someobject",
Bucket = examplebucket.Id,
Source = new FileAsset("index.html"),
ServerSideEncryption = "AES256",
});
});
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 {
examplebucket, err := s3.NewBucket(ctx, "examplebucket", &s3.BucketArgs{
Bucket: pulumi.String("examplebuckettftest"),
})
if err != nil {
return err
}
_, err = s3.NewBucketAcl(ctx, "example", &s3.BucketAclArgs{
Bucket: examplebucket.ID().ToIDOutput().ToStringOutput(),
Acl: pulumi.String("private"),
})
if err != nil {
return err
}
_, err = s3.NewBucketObjectv2(ctx, "example", &s3.BucketObjectv2Args{
Key: pulumi.String("someobject"),
Bucket: examplebucket.ID().ToIDOutput().ToStringOutput(),
Source: pulumi.NewFileAsset("index.html"),
ServerSideEncryption: pulumi.String("AES256"),
})
if err != nil {
return err
}
return nil
})
}
pulumi {
required_providers {
aws = {
source = "pulumi/aws"
}
}
}
resource "aws_s3_bucket" "examplebucket" {
bucket = "examplebuckettftest"
}
resource "aws_s3_bucketacl" "example" {
bucket = aws_s3_bucket.examplebucket.id
acl = "private"
}
resource "aws_s3_bucketobjectv2" "example" {
key = "someobject"
bucket = aws_s3_bucket.examplebucket.id
source = fileAsset("index.html")
server_side_encryption = "AES256"
}
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 com.pulumi.aws.s3.BucketAcl;
import com.pulumi.aws.s3.BucketAclArgs;
import com.pulumi.aws.s3.BucketObjectv2;
import com.pulumi.aws.s3.BucketObjectv2Args;
import com.pulumi.asset.FileAsset;
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 examplebucket = new Bucket("examplebucket", BucketArgs.builder()
.bucket("examplebuckettftest")
.build());
var example = new BucketAcl("example", BucketAclArgs.builder()
.bucket(examplebucket.id())
.acl("private")
.build());
var exampleBucketObjectv2 = new BucketObjectv2("exampleBucketObjectv2", BucketObjectv2Args.builder()
.key("someobject")
.bucket(examplebucket.id())
.source(new FileAsset("index.html"))
.serverSideEncryption("AES256")
.build());
}
}
resources:
examplebucket:
type: aws:s3:Bucket
properties:
bucket: examplebuckettftest
example:
type: aws:s3:BucketAcl
properties:
bucket: ${examplebucket.id}
acl: private
exampleBucketObjectv2:
type: aws:s3:BucketObjectv2
name: example
properties:
key: someobject
bucket: ${examplebucket.id}
source:
fn::fileAsset: index.html
serverSideEncryption: AES256
S3 Object Lock
import * as pulumi from "@pulumi/pulumi";
import * as aws from "@pulumi/aws";
const examplebucket = new aws.s3.Bucket("examplebucket", {
bucket: "examplebuckettftest",
objectLockEnabled: true,
});
const example = new aws.s3.BucketAcl("example", {
bucket: examplebucket.id,
acl: "private",
});
const exampleBucketVersioning = new aws.s3.BucketVersioning("example", {
versioningConfiguration: {
status: "Enabled",
},
bucket: examplebucket.id,
});
const examplebucketObject = new aws.s3.BucketObjectv2("examplebucket_object", {
key: "someobject",
bucket: examplebucket.id,
source: new pulumi.asset.FileAsset("important.txt"),
objectLockLegalHoldStatus: "ON",
objectLockMode: "GOVERNANCE",
objectLockRetainUntilDate: "2021-12-31T23:59:60Z",
forceDestroy: true,
}, {
dependsOn: [exampleBucketVersioning],
});
import pulumi
import pulumi_aws as aws
examplebucket = aws.s3.Bucket("examplebucket",
bucket="examplebuckettftest",
object_lock_enabled=True)
example = aws.s3.BucketAcl("example",
bucket=examplebucket.id,
acl="private")
example_bucket_versioning = aws.s3.BucketVersioning("example",
versioning_configuration={
"status": "Enabled",
},
bucket=examplebucket.id)
examplebucket_object = aws.s3.BucketObjectv2("examplebucket_object",
key="someobject",
bucket=examplebucket.id,
source=pulumi.FileAsset("important.txt"),
object_lock_legal_hold_status="ON",
object_lock_mode="GOVERNANCE",
object_lock_retain_until_date="2021-12-31T23:59:60Z",
force_destroy=True,
opts = pulumi.ResourceOptions(depends_on=[example_bucket_versioning]))
using System.Collections.Generic;
using System.Linq;
using Pulumi;
using Aws = Pulumi.Aws;
return await Deployment.RunAsync(() =>
{
var examplebucket = new Aws.S3.Bucket("examplebucket", new()
{
BucketName = "examplebuckettftest",
ObjectLockEnabled = true,
});
var example = new Aws.S3.BucketAcl("example", new()
{
Bucket = examplebucket.Id,
Acl = "private",
});
var exampleBucketVersioning = new Aws.S3.BucketVersioning("example", new()
{
VersioningConfiguration = new Aws.S3.Inputs.BucketVersioningVersioningConfigurationArgs
{
Status = "Enabled",
},
Bucket = examplebucket.Id,
});
var examplebucketObject = new Aws.S3.BucketObjectv2("examplebucket_object", new()
{
Key = "someobject",
Bucket = examplebucket.Id,
Source = new FileAsset("important.txt"),
ObjectLockLegalHoldStatus = "ON",
ObjectLockMode = "GOVERNANCE",
ObjectLockRetainUntilDate = "2021-12-31T23:59:60Z",
ForceDestroy = true,
}, new CustomResourceOptions
{
DependsOn =
{
exampleBucketVersioning,
},
});
});
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 {
examplebucket, err := s3.NewBucket(ctx, "examplebucket", &s3.BucketArgs{
Bucket: pulumi.String("examplebuckettftest"),
ObjectLockEnabled: pulumi.Bool(true),
})
if err != nil {
return err
}
_, err = s3.NewBucketAcl(ctx, "example", &s3.BucketAclArgs{
Bucket: examplebucket.ID().ToIDOutput().ToStringOutput(),
Acl: pulumi.String("private"),
})
if err != nil {
return err
}
exampleBucketVersioning, err := s3.NewBucketVersioning(ctx, "example", &s3.BucketVersioningArgs{
VersioningConfiguration: &s3.BucketVersioningVersioningConfigurationArgs{
Status: pulumi.String("Enabled"),
},
Bucket: examplebucket.ID().ToIDOutput().ToStringOutput(),
})
if err != nil {
return err
}
_, err = s3.NewBucketObjectv2(ctx, "examplebucket_object", &s3.BucketObjectv2Args{
Key: pulumi.String("someobject"),
Bucket: examplebucket.ID().ToIDOutput().ToStringOutput(),
Source: pulumi.NewFileAsset("important.txt"),
ObjectLockLegalHoldStatus: pulumi.String("ON"),
ObjectLockMode: pulumi.String("GOVERNANCE"),
ObjectLockRetainUntilDate: pulumi.String("2021-12-31T23:59:60Z"),
ForceDestroy: pulumi.Bool(true),
}, pulumi.DependsOn([]pulumi.Resource{
exampleBucketVersioning,
}))
if err != nil {
return err
}
return nil
})
}
pulumi {
required_providers {
aws = {
source = "pulumi/aws"
}
}
}
resource "aws_s3_bucket" "examplebucket" {
bucket = "examplebuckettftest"
object_lock_enabled = true
}
resource "aws_s3_bucketacl" "example" {
bucket = aws_s3_bucket.examplebucket.id
acl = "private"
}
resource "aws_s3_bucketversioning" "example" {
versioning_configuration = {
status = "Enabled"
}
bucket = aws_s3_bucket.examplebucket.id
}
resource "aws_s3_bucketobjectv2" "examplebucket_object" {
depends_on = [aws_s3_bucketversioning.example]
key = "someobject"
bucket = aws_s3_bucket.examplebucket.id
source = fileAsset("important.txt")
object_lock_legal_hold_status = "ON"
object_lock_mode = "GOVERNANCE"
object_lock_retain_until_date = "2021-12-31T23:59:60Z"
force_destroy = true
}
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 com.pulumi.aws.s3.BucketAcl;
import com.pulumi.aws.s3.BucketAclArgs;
import com.pulumi.aws.s3.BucketVersioning;
import com.pulumi.aws.s3.BucketVersioningArgs;
import com.pulumi.aws.s3.inputs.BucketVersioningVersioningConfigurationArgs;
import com.pulumi.aws.s3.BucketObjectv2;
import com.pulumi.aws.s3.BucketObjectv2Args;
import com.pulumi.asset.FileAsset;
import com.pulumi.resources.CustomResourceOptions;
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 examplebucket = new Bucket("examplebucket", BucketArgs.builder()
.bucket("examplebuckettftest")
.objectLockEnabled(true)
.build());
var example = new BucketAcl("example", BucketAclArgs.builder()
.bucket(examplebucket.id())
.acl("private")
.build());
var exampleBucketVersioning = new BucketVersioning("exampleBucketVersioning", BucketVersioningArgs.builder()
.versioningConfiguration(BucketVersioningVersioningConfigurationArgs.builder()
.status("Enabled")
.build())
.bucket(examplebucket.id())
.build());
var examplebucketObject = new BucketObjectv2("examplebucketObject", BucketObjectv2Args.builder()
.key("someobject")
.bucket(examplebucket.id())
.source(new FileAsset("important.txt"))
.objectLockLegalHoldStatus("ON")
.objectLockMode("GOVERNANCE")
.objectLockRetainUntilDate("2021-12-31T23:59:60Z")
.forceDestroy(true)
.build(), CustomResourceOptions.builder()
.dependsOn(exampleBucketVersioning)
.build());
}
}
resources:
examplebucket:
type: aws:s3:Bucket
properties:
bucket: examplebuckettftest
objectLockEnabled: true
example:
type: aws:s3:BucketAcl
properties:
bucket: ${examplebucket.id}
acl: private
exampleBucketVersioning:
type: aws:s3:BucketVersioning
name: example
properties:
versioningConfiguration:
status: Enabled
bucket: ${examplebucket.id}
examplebucketObject:
type: aws:s3:BucketObjectv2
name: examplebucket_object
properties:
key: someobject
bucket: ${examplebucket.id}
source:
fn::fileAsset: important.txt
objectLockLegalHoldStatus: ON
objectLockMode: GOVERNANCE
objectLockRetainUntilDate: 2021-12-31T23:59:60Z
forceDestroy: true
options:
dependsOn:
- ${exampleBucketVersioning}
Ignoring Provider defaultTags
S3 objects support a maximum of 10 tags.
If the resource's own tags and the provider-level defaultTags would together lead to more than 10 tags on an S3 object, use the overrideProvider configuration block to suppress any provider-level defaultTags.
> S3 objects stored in Amazon S3 Express directory buckets do not support tags, so any provider-level defaultTags must be suppressed.
import * as pulumi from "@pulumi/pulumi";
import * as aws from "@pulumi/aws";
const examplebucket = new aws.s3.Bucket("examplebucket", {bucket: "examplebuckettftest"});
const examplebucketObject = new aws.s3.BucketObjectv2("examplebucket_object", {
overrideProvider: {
defaultTags: {
tags: {},
},
},
key: "someobject",
bucket: examplebucket.id,
source: new pulumi.asset.FileAsset("important.txt"),
tags: {
Env: "test",
},
});
import pulumi
import pulumi_aws as aws
examplebucket = aws.s3.Bucket("examplebucket", bucket="examplebuckettftest")
examplebucket_object = aws.s3.BucketObjectv2("examplebucket_object",
override_provider={
"default_tags": {
"tags": {},
},
},
key="someobject",
bucket=examplebucket.id,
source=pulumi.FileAsset("important.txt"),
tags={
"Env": "test",
})
using System.Collections.Generic;
using System.Linq;
using Pulumi;
using Aws = Pulumi.Aws;
return await Deployment.RunAsync(() =>
{
var examplebucket = new Aws.S3.Bucket("examplebucket", new()
{
BucketName = "examplebuckettftest",
});
var examplebucketObject = new Aws.S3.BucketObjectv2("examplebucket_object", new()
{
OverrideProvider = new Aws.S3.Inputs.BucketObjectv2OverrideProviderArgs
{
DefaultTags = new Aws.S3.Inputs.BucketObjectv2OverrideProviderDefaultTagsArgs
{
Tags = null,
},
},
Key = "someobject",
Bucket = examplebucket.Id,
Source = new FileAsset("important.txt"),
Tags =
{
{ "Env", "test" },
},
});
});
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 {
examplebucket, err := s3.NewBucket(ctx, "examplebucket", &s3.BucketArgs{
Bucket: pulumi.String("examplebuckettftest"),
})
if err != nil {
return err
}
_, err = s3.NewBucketObjectv2(ctx, "examplebucket_object", &s3.BucketObjectv2Args{
OverrideProvider: &s3.BucketObjectv2OverrideProviderArgs{
DefaultTags: &s3.BucketObjectv2OverrideProviderDefaultTagsArgs{
Tags: pulumi.StringMap{},
},
},
Key: pulumi.String("someobject"),
Bucket: examplebucket.ID().ToIDOutput().ToStringOutput(),
Source: pulumi.NewFileAsset("important.txt"),
Tags: pulumi.StringMap{
"Env": pulumi.String("test"),
},
})
if err != nil {
return err
}
return nil
})
}
pulumi {
required_providers {
aws = {
source = "pulumi/aws"
}
}
}
resource "aws_s3_bucket" "examplebucket" {
bucket = "examplebuckettftest"
}
resource "aws_s3_bucketobjectv2" "examplebucket_object" {
override_provider = {
default_tags = {
tags = {}
}
}
key = "someobject"
bucket = aws_s3_bucket.examplebucket.id
source = fileAsset("important.txt")
tags = {
"Env" = "test"
}
}
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 com.pulumi.aws.s3.BucketObjectv2;
import com.pulumi.aws.s3.BucketObjectv2Args;
import com.pulumi.aws.s3.inputs.BucketObjectv2OverrideProviderArgs;
import com.pulumi.aws.s3.inputs.BucketObjectv2OverrideProviderDefaultTagsArgs;
import com.pulumi.asset.FileAsset;
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 examplebucket = new Bucket("examplebucket", BucketArgs.builder()
.bucket("examplebuckettftest")
.build());
var examplebucketObject = new BucketObjectv2("examplebucketObject", BucketObjectv2Args.builder()
.overrideProvider(BucketObjectv2OverrideProviderArgs.builder()
.defaultTags(BucketObjectv2OverrideProviderDefaultTagsArgs.builder()
.tags(Map.ofEntries(
))
.build())
.build())
.key("someobject")
.bucket(examplebucket.id())
.source(new FileAsset("important.txt"))
.tags(Map.of("Env", "test"))
.build());
}
}
resources:
examplebucket:
type: aws:s3:Bucket
properties:
bucket: examplebuckettftest
examplebucketObject:
type: aws:s3:BucketObjectv2
name: examplebucket_object
properties:
overrideProvider:
defaultTags:
tags: {}
key: someobject
bucket: ${examplebucket.id}
source:
fn::fileAsset: important.txt
tags:
Env: test
Import
Identity Schema
Required
bucket(String) S3 bucket name.key(String) Object key.
Optional
accountId(String) AWS Account where this resource is managed.region(String) Region where this resource is managed.
Import using S3 URL syntax:
Using pulumi import to import objects using the id or S3 URL. For example:
Import using the id, which is the bucket name and the key together:
$ pulumi import aws:s3/bucketObjectv2:BucketObjectv2 example some-bucket-name/some/key.txt
Import using S3 URL syntax:
$ pulumi import aws:s3/bucketObjectv2:BucketObjectv2 example s3://some-bucket-name/some/key.txt
Constructors
- BucketObjectv2(String name, {BucketObjectv2Args? args, CustomResourceOptions? options})
-
Creates a new BucketObjectv2.
nameThe Pulumi resource name.argsArguments used to configure this BucketObjectv2. The set of arguments for BucketObjectv2.optionsResource options controlling this resource's behavior. - BucketObjectv2.reference(String urn)
- Creates a typed reference to an existing BucketObjectv2 resource.
Properties
-
acl
↔ Output<
String> -
Canned ACL to apply. Valid values are
private,public-read,public-read-write,aws-exec-read,authenticated-read,bucket-owner-read, andbucket-owner-full-control.latefinal -
arn
↔ Output<
String> -
ARN of the object.
latefinal
-
bucket
↔ Output<
String> -
Name of the bucket to put the file in. Alternatively, an S3 access point ARN can be specified.
latefinal
-
bucketKeyEnabled
↔ Output<
bool> -
Whether or not to use Amazon S3 Bucket Keys for SSE-KMS.
latefinal
-
cacheControl
↔ Output<
String?> -
Caching behavior along the request/reply chain Read w3c cacheControl for further details.
latefinal
-
checksumAlgorithm
↔ Output<
String?> -
Algorithm used to create the checksum for the object. If a value is specified and the object is encrypted with KMS, you must have permission to use the
kms:Decryptaction. Valid values:CRC32,CRC32C,CRC64NVME,SHA1,SHA256.latefinal -
checksumCrc32
↔ Output<
String> -
Base64-encoded, 32-bit CRC32 checksum of the object.
latefinal
-
checksumCrc32c
↔ Output<
String> -
Base64-encoded, 32-bit CRC32C checksum of the object.
latefinal
-
checksumCrc64nvme
↔ Output<
String> -
Base64-encoded, 64-bit CRC64NVME checksum of the object.
latefinal
-
checksumSha1
↔ Output<
String> -
Base64-encoded, 160-bit SHA-1 digest of the object.
latefinal
-
checksumSha256
↔ Output<
String> -
Base64-encoded, 256-bit SHA-256 digest of the object.
latefinal
-
childResources
→ Set<
Resource> -
finalinherited
-
completionSources
↔ Map<
String, IOutputCompletionSource> -
latefinalinherited
-
content
↔ Output<
String?> -
Literal string value to use as the object content, which will be uploaded as UTF-8-encoded text.
latefinal
-
contentBase64
↔ Output<
String?> -
Base64-encoded data that will be decoded and uploaded as raw bytes for the object content. This allows safely uploading non-UTF8 binary data, but is recommended only for small content such as the result of the
gzipbase64function with small text strings. For larger objects, usesourceto stream the content from a disk file.latefinal -
contentDisposition
↔ Output<
String?> -
Presentational information for the object. Read w3c contentDisposition for further information.
latefinal
-
contentEncoding
↔ Output<
String?> -
Content encodings that have been applied to the object and thus what decoding mechanisms must be applied to obtain the media-type referenced by the Content-Type header field. Read w3c content encoding for further information.
latefinal
-
contentLanguage
↔ Output<
String?> -
Language the content is in e.g., en-US or en-GB.
latefinal
-
contentType
↔ Output<
String> -
Standard MIME type describing the format of the object data, e.g., application/octet-stream. All Valid MIME Types are valid for this input.
latefinal
-
etag
↔ Output<
String> -
Triggers updates when the value changes. This attribute is not compatible with KMS encryption,
kmsKeyIdorserverSideEncryption = "aws:kms", also if an object is larger than 16 MB, the AWS Management Console will upload or copy that object as a Multipart Upload, and therefore the ETag will not be an MD5 digest (seesourceHashinstead).latefinal -
forceDestroy
↔ Output<
bool?> -
Whether to allow the object to be deleted by removing any legal hold on any object version. Default is
false. This value should be set totrueonly if the bucket has S3 object lock enabled.latefinal - hashCode → int
-
The hash code for this object.
no setterinherited
-
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
-
key
↔ Output<
String> -
Name of the object once it is in the bucket.
latefinal
-
kmsKeyId
↔ Output<
String> -
ARN of the KMS Key to use for object encryption. If the S3 Bucket has server-side encryption enabled, that value will automatically be used. If referencing the
aws.kms.Keyresource, use thearnattribute. If referencing theaws.kms.Aliasdata source or resource, use thetargetKeyArnattribute. The provider will only perform drift detection if a configuration value is provided.latefinal -
metadata
↔ Output<
Map< String, String> ?> -
Map of keys/values to provision metadata (will be automatically prefixed by
x-amz-meta-, note that only lowercase label are currently supported by the AWS Go API).latefinal -
objectLockLegalHoldStatus
↔ Output<
String?> -
Legal hold status that you want to apply to the specified object. Valid values are
ONandOFF.latefinal -
objectLockMode
↔ Output<
String?> -
Object lock retention mode that you want to apply to this object. Valid values are
GOVERNANCEandCOMPLIANCE.latefinal -
objectLockRetainUntilDate
↔ Output<
String?> -
Date and time, in RFC3339 format, when this object's object lock will expire.
latefinal
-
overrideProvider
↔ Output<
BucketObjectv2OverrideProvider?> -
Override provider-level configuration options. See
overrideProviderBlock below for more details.latefinal -
region
↔ Output<
String> -
Region where this resource will be managed. Defaults to the Region set in the provider configuration.
latefinal
-
resourceTransforms
→ List<
ResourceTransform> -
Inherited/explicit async transforms.
no setterinherited
- runtimeType → Type
-
A representation of the runtime type of the object.
no setterinherited
-
serverSideEncryption
↔ Output<
String> -
Server-side encryption of the object in S3. Valid values are
"AES256","aws:kms","aws:kms:dsse", and"aws:fsx".latefinal - source ↔ Output
-
Path to a file that will be read and uploaded as raw bytes for the object content.
latefinal
-
sourceHash
↔ Output<
String?> -
Triggers updates like
etagbut useful to addressetagencryption limitations. (The value is only stored in state and not saved by AWS.)latefinal -
storageClass
↔ Output<
String> -
Storage Class for the object. Defaults to "
STANDARD".latefinal -
Map of tags to assign to the object. 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
-
versionId
↔ Output<
String> -
Unique version ID value for the object, if bucket versioning is enabled.
latefinal
-
websiteRedirect
↔ Output<
String?> -
Target URL for website redirect.
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
Static Methods
-
get(
String name, Input< String> id, {BucketObjectv2State? state, CustomResourceOptions? options}) → BucketObjectv2 -
Gets an existing BucketObjectv2 resource's state with the given
nameandid.