BucketLoggingV2

Provides an S3 bucket (server access) logging resource. For more information, see Logging requests using server access logging in the AWS S3 User Guide.

Note: Amazon S3 supports server access logging, AWS CloudTrail, or a combination of both. Refer to the Logging options for Amazon S3 to decide which method meets your requirements.

Example Usage

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

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

    var exampleBucketAclV2 = new Aws.S3.BucketAclV2("exampleBucketAclV2", new()
    {
        Bucket = exampleBucketV2.Id,
        Acl = "private",
    });

    var logBucket = new Aws.S3.BucketV2("logBucket");

    var logBucketAcl = new Aws.S3.BucketAclV2("logBucketAcl", new()
    {
        Bucket = logBucket.Id,
        Acl = "log-delivery-write",
    });

    var exampleBucketLoggingV2 = new Aws.S3.BucketLoggingV2("exampleBucketLoggingV2", new()
    {
        Bucket = exampleBucketV2.Id,
        TargetBucket = logBucket.Id,
        TargetPrefix = "log/",
    });

});
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.NewBucketAclV2(ctx, "exampleBucketAclV2", &s3.BucketAclV2Args{
			Bucket: exampleBucketV2.ID(),
			Acl:    pulumi.String("private"),
		})
		if err != nil {
			return err
		}
		logBucket, err := s3.NewBucketV2(ctx, "logBucket", nil)
		if err != nil {
			return err
		}
		_, err = s3.NewBucketAclV2(ctx, "logBucketAcl", &s3.BucketAclV2Args{
			Bucket: logBucket.ID(),
			Acl:    pulumi.String("log-delivery-write"),
		})
		if err != nil {
			return err
		}
		_, err = s3.NewBucketLoggingV2(ctx, "exampleBucketLoggingV2", &s3.BucketLoggingV2Args{
			Bucket:       exampleBucketV2.ID(),
			TargetBucket: logBucket.ID(),
			TargetPrefix: pulumi.String("log/"),
		})
		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.BucketAclV2;
import com.pulumi.aws.s3.BucketAclV2Args;
import com.pulumi.aws.s3.BucketLoggingV2;
import com.pulumi.aws.s3.BucketLoggingV2Args;
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 exampleBucketAclV2 = new BucketAclV2("exampleBucketAclV2", BucketAclV2Args.builder()        
            .bucket(exampleBucketV2.id())
            .acl("private")
            .build());

        var logBucket = new BucketV2("logBucket");

        var logBucketAcl = new BucketAclV2("logBucketAcl", BucketAclV2Args.builder()        
            .bucket(logBucket.id())
            .acl("log-delivery-write")
            .build());

        var exampleBucketLoggingV2 = new BucketLoggingV2("exampleBucketLoggingV2", BucketLoggingV2Args.builder()        
            .bucket(exampleBucketV2.id())
            .targetBucket(logBucket.id())
            .targetPrefix("log/")
            .build());

    }
}
import pulumi
import pulumi_aws as aws

example_bucket_v2 = aws.s3.BucketV2("exampleBucketV2")
example_bucket_acl_v2 = aws.s3.BucketAclV2("exampleBucketAclV2",
    bucket=example_bucket_v2.id,
    acl="private")
log_bucket = aws.s3.BucketV2("logBucket")
log_bucket_acl = aws.s3.BucketAclV2("logBucketAcl",
    bucket=log_bucket.id,
    acl="log-delivery-write")
example_bucket_logging_v2 = aws.s3.BucketLoggingV2("exampleBucketLoggingV2",
    bucket=example_bucket_v2.id,
    target_bucket=log_bucket.id,
    target_prefix="log/")
import * as pulumi from "@pulumi/pulumi";
import * as aws from "@pulumi/aws";

const exampleBucketV2 = new aws.s3.BucketV2("exampleBucketV2", {});
const exampleBucketAclV2 = new aws.s3.BucketAclV2("exampleBucketAclV2", {
    bucket: exampleBucketV2.id,
    acl: "private",
});
const logBucket = new aws.s3.BucketV2("logBucket", {});
const logBucketAcl = new aws.s3.BucketAclV2("logBucketAcl", {
    bucket: logBucket.id,
    acl: "log-delivery-write",
});
const exampleBucketLoggingV2 = new aws.s3.BucketLoggingV2("exampleBucketLoggingV2", {
    bucket: exampleBucketV2.id,
    targetBucket: logBucket.id,
    targetPrefix: "log/",
});
resources:
  exampleBucketV2:
    type: aws:s3:BucketV2
  exampleBucketAclV2:
    type: aws:s3:BucketAclV2
    properties:
      bucket: ${exampleBucketV2.id}
      acl: private
  logBucket:
    type: aws:s3:BucketV2
  logBucketAcl:
    type: aws:s3:BucketAclV2
    properties:
      bucket: ${logBucket.id}
      acl: log-delivery-write
  exampleBucketLoggingV2:
    type: aws:s3:BucketLoggingV2
    properties:
      bucket: ${exampleBucketV2.id}
      targetBucket: ${logBucket.id}
      targetPrefix: log/

Create BucketLoggingV2 Resource

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

name string
The unique name of the resource.
args BucketLoggingV2Args
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 BucketLoggingV2Args
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 BucketLoggingV2Args
The arguments to resource properties.
opts ResourceOption
Bag of options to control resource's behavior.
name string
The unique name of the resource.
args BucketLoggingV2Args
The arguments to resource properties.
opts CustomResourceOptions
Bag of options to control resource's behavior.
name String
The unique name of the resource.
args BucketLoggingV2Args
The arguments to resource properties.
options CustomResourceOptions
Bag of options to control resource's behavior.

BucketLoggingV2 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 BucketLoggingV2 resource accepts the following input properties:

Bucket string

The name of the bucket.

TargetBucket string

The name of the bucket where you want Amazon S3 to store server access logs.

TargetPrefix string

A prefix for all log object keys.

ExpectedBucketOwner string

The account ID of the expected bucket owner.

TargetGrants List<BucketLoggingV2TargetGrantArgs>

Set of configuration blocks with information for granting permissions documented below.

Bucket string

The name of the bucket.

TargetBucket string

The name of the bucket where you want Amazon S3 to store server access logs.

TargetPrefix string

A prefix for all log object keys.

ExpectedBucketOwner string

The account ID of the expected bucket owner.

TargetGrants []BucketLoggingV2TargetGrantArgs

Set of configuration blocks with information for granting permissions documented below.

bucket String

The name of the bucket.

targetBucket String

The name of the bucket where you want Amazon S3 to store server access logs.

targetPrefix String

A prefix for all log object keys.

expectedBucketOwner String

The account ID of the expected bucket owner.

targetGrants List<BucketLoggingV2TargetGrantArgs>

Set of configuration blocks with information for granting permissions documented below.

bucket string

The name of the bucket.

targetBucket string

The name of the bucket where you want Amazon S3 to store server access logs.

targetPrefix string

A prefix for all log object keys.

expectedBucketOwner string

The account ID of the expected bucket owner.

targetGrants BucketLoggingV2TargetGrantArgs[]

Set of configuration blocks with information for granting permissions documented below.

bucket str

The name of the bucket.

target_bucket str

The name of the bucket where you want Amazon S3 to store server access logs.

target_prefix str

A prefix for all log object keys.

expected_bucket_owner str

The account ID of the expected bucket owner.

target_grants Sequence[BucketLoggingV2TargetGrantArgs]

Set of configuration blocks with information for granting permissions documented below.

bucket String

The name of the bucket.

targetBucket String

The name of the bucket where you want Amazon S3 to store server access logs.

targetPrefix String

A prefix for all log object keys.

expectedBucketOwner String

The account ID of the expected bucket owner.

targetGrants List<Property Map>

Set of configuration blocks with information for granting permissions documented below.

Outputs

All input properties are implicitly available as output properties. Additionally, the BucketLoggingV2 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 BucketLoggingV2 Resource

Get an existing BucketLoggingV2 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?: BucketLoggingV2State, opts?: CustomResourceOptions): BucketLoggingV2
@staticmethod
def get(resource_name: str,
        id: str,
        opts: Optional[ResourceOptions] = None,
        bucket: Optional[str] = None,
        expected_bucket_owner: Optional[str] = None,
        target_bucket: Optional[str] = None,
        target_grants: Optional[Sequence[BucketLoggingV2TargetGrantArgs]] = None,
        target_prefix: Optional[str] = None) -> BucketLoggingV2
func GetBucketLoggingV2(ctx *Context, name string, id IDInput, state *BucketLoggingV2State, opts ...ResourceOption) (*BucketLoggingV2, error)
public static BucketLoggingV2 Get(string name, Input<string> id, BucketLoggingV2State? state, CustomResourceOptions? opts = null)
public static BucketLoggingV2 get(String name, Output<String> id, BucketLoggingV2State 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

The name of the bucket.

ExpectedBucketOwner string

The account ID of the expected bucket owner.

TargetBucket string

The name of the bucket where you want Amazon S3 to store server access logs.

TargetGrants List<BucketLoggingV2TargetGrantArgs>

Set of configuration blocks with information for granting permissions documented below.

TargetPrefix string

A prefix for all log object keys.

Bucket string

The name of the bucket.

ExpectedBucketOwner string

The account ID of the expected bucket owner.

TargetBucket string

The name of the bucket where you want Amazon S3 to store server access logs.

TargetGrants []BucketLoggingV2TargetGrantArgs

Set of configuration blocks with information for granting permissions documented below.

TargetPrefix string

A prefix for all log object keys.

bucket String

The name of the bucket.

expectedBucketOwner String

The account ID of the expected bucket owner.

targetBucket String

The name of the bucket where you want Amazon S3 to store server access logs.

targetGrants List<BucketLoggingV2TargetGrantArgs>

Set of configuration blocks with information for granting permissions documented below.

targetPrefix String

A prefix for all log object keys.

bucket string

The name of the bucket.

expectedBucketOwner string

The account ID of the expected bucket owner.

targetBucket string

The name of the bucket where you want Amazon S3 to store server access logs.

targetGrants BucketLoggingV2TargetGrantArgs[]

Set of configuration blocks with information for granting permissions documented below.

targetPrefix string

A prefix for all log object keys.

bucket str

The name of the bucket.

expected_bucket_owner str

The account ID of the expected bucket owner.

target_bucket str

The name of the bucket where you want Amazon S3 to store server access logs.

target_grants Sequence[BucketLoggingV2TargetGrantArgs]

Set of configuration blocks with information for granting permissions documented below.

target_prefix str

A prefix for all log object keys.

bucket String

The name of the bucket.

expectedBucketOwner String

The account ID of the expected bucket owner.

targetBucket String

The name of the bucket where you want Amazon S3 to store server access logs.

targetGrants List<Property Map>

Set of configuration blocks with information for granting permissions documented below.

targetPrefix String

A prefix for all log object keys.

Supporting Types

BucketLoggingV2TargetGrant

Grantee BucketLoggingV2TargetGrantGrantee

A configuration block for the person being granted permissions documented below.

Permission string

Logging permissions assigned to the grantee for the bucket. Valid values: FULL_CONTROL, READ, WRITE.

Grantee BucketLoggingV2TargetGrantGrantee

A configuration block for the person being granted permissions documented below.

Permission string

Logging permissions assigned to the grantee for the bucket. Valid values: FULL_CONTROL, READ, WRITE.

grantee BucketLoggingV2TargetGrantGrantee

A configuration block for the person being granted permissions documented below.

permission String

Logging permissions assigned to the grantee for the bucket. Valid values: FULL_CONTROL, READ, WRITE.

grantee BucketLoggingV2TargetGrantGrantee

A configuration block for the person being granted permissions documented below.

permission string

Logging permissions assigned to the grantee for the bucket. Valid values: FULL_CONTROL, READ, WRITE.

grantee BucketLoggingV2TargetGrantGrantee

A configuration block for the person being granted permissions documented below.

permission str

Logging permissions assigned to the grantee for the bucket. Valid values: FULL_CONTROL, READ, WRITE.

grantee Property Map

A configuration block for the person being granted permissions documented below.

permission String

Logging permissions assigned to the grantee for the bucket. Valid values: FULL_CONTROL, READ, WRITE.

BucketLoggingV2TargetGrantGrantee

Type string

Type of grantee. Valid values: CanonicalUser, AmazonCustomerByEmail, Group.

DisplayName string
EmailAddress string

Email address of the grantee. See Regions and Endpoints for supported AWS regions where this argument can be specified.

Id string

The canonical user ID of the grantee.

Uri string

URI of the grantee group.

Type string

Type of grantee. Valid values: CanonicalUser, AmazonCustomerByEmail, Group.

DisplayName string
EmailAddress string

Email address of the grantee. See Regions and Endpoints for supported AWS regions where this argument can be specified.

Id string

The canonical user ID of the grantee.

Uri string

URI of the grantee group.

type String

Type of grantee. Valid values: CanonicalUser, AmazonCustomerByEmail, Group.

displayName String
emailAddress String

Email address of the grantee. See Regions and Endpoints for supported AWS regions where this argument can be specified.

id String

The canonical user ID of the grantee.

uri String

URI of the grantee group.

type string

Type of grantee. Valid values: CanonicalUser, AmazonCustomerByEmail, Group.

displayName string
emailAddress string

Email address of the grantee. See Regions and Endpoints for supported AWS regions where this argument can be specified.

id string

The canonical user ID of the grantee.

uri string

URI of the grantee group.

type str

Type of grantee. Valid values: CanonicalUser, AmazonCustomerByEmail, Group.

display_name str
email_address str

Email address of the grantee. See Regions and Endpoints for supported AWS regions where this argument can be specified.

id str

The canonical user ID of the grantee.

uri str

URI of the grantee group.

type String

Type of grantee. Valid values: CanonicalUser, AmazonCustomerByEmail, Group.

displayName String
emailAddress String

Email address of the grantee. See Regions and Endpoints for supported AWS regions where this argument can be specified.

id String

The canonical user ID of the grantee.

uri String

URI of the grantee group.

Import

S3 bucket logging 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 logging resource should be imported using the bucket e.g.,

 $ pulumi import aws:s3/bucketLoggingV2:BucketLoggingV2 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 logging resource should be imported using the bucket and expected_bucket_owner separated by a comma (,) e.g.,

 $ pulumi import aws:s3/bucketLoggingV2:BucketLoggingV2 example bucket-name,123456789012

Package Details

Repository
https://github.com/pulumi/pulumi-aws
License
Apache-2.0
Notes

This Pulumi package is based on the aws Terraform Provider.