Show / Hide Table of Contents

Class BucketNotification

Manages a S3 Bucket Notification Configuration. For additional information, see the Configuring S3 Event Notifications section in the Amazon S3 Developer Guide.

NOTE: S3 Buckets only support a single notification configuration. Declaring multiple aws.s3.BucketNotification resources to the same S3 Bucket will cause a perpetual difference in configuration. See the example "Trigger multiple Lambda functions" for an option.

Example Usage

Add notification configuration to SNS Topic

using Pulumi;
using Aws = Pulumi.Aws;

class MyStack : Stack
{
public MyStack()
{
    var bucket = new Aws.S3.Bucket("bucket", new Aws.S3.BucketArgs
    {
    });
    var topic = new Aws.Sns.Topic("topic", new Aws.Sns.TopicArgs
    {
        Policy = bucket.Arn.Apply(arn => @$"{{
""Version"":""2012-10-17"",
""Statement"":[{{
    ""Effect"": ""Allow"",
    ""Principal"": {{""AWS"":""*""}},
    ""Action"": ""SNS:Publish"",
    ""Resource"": ""arn:aws:sns:*:*:s3-event-notification-topic"",
    ""Condition"":{{
        ""ArnLike"":{{""aws:SourceArn"":""{arn}""}}
    }}
}}]
}}

"),
    });
    var bucketNotification = new Aws.S3.BucketNotification("bucketNotification", new Aws.S3.BucketNotificationArgs
    {
        Bucket = bucket.Id,
        Topics = 
        {
            new Aws.S3.Inputs.BucketNotificationTopicArgs
            {
                Events = 
                {
                    "s3:ObjectCreated:*",
                },
                FilterSuffix = ".log",
                TopicArn = topic.Arn,
            },
        },
    });
}

}

Add notification configuration to SQS Queue

using Pulumi;
using Aws = Pulumi.Aws;

class MyStack : Stack
{
public MyStack()
{
    var bucket = new Aws.S3.Bucket("bucket", new Aws.S3.BucketArgs
    {
    });
    var queue = new Aws.Sqs.Queue("queue", new Aws.Sqs.QueueArgs
    {
        Policy = bucket.Arn.Apply(arn => @$"{{
""Version"": ""2012-10-17"",
""Statement"": [
{{
  ""Effect"": ""Allow"",
  ""Principal"": ""*"",
  ""Action"": ""sqs:SendMessage"",
""Resource"": ""arn:aws:sqs:*:*:s3-event-notification-queue"",
  ""Condition"": {{
    ""ArnEquals"": {{ ""aws:SourceArn"": ""{arn}"" }}
  }}
}}
]
}}

"),
    });
    var bucketNotification = new Aws.S3.BucketNotification("bucketNotification", new Aws.S3.BucketNotificationArgs
    {
        Bucket = bucket.Id,
        Queues = 
        {
            new Aws.S3.Inputs.BucketNotificationQueueArgs
            {
                Events = 
                {
                    "s3:ObjectCreated:*",
                },
                FilterSuffix = ".log",
                QueueArn = queue.Arn,
            },
        },
    });
}

}

Add multiple notification configurations to SQS Queue

using Pulumi;
using Aws = Pulumi.Aws;

class MyStack : Stack
{
public MyStack()
{
    var bucket = new Aws.S3.Bucket("bucket", new Aws.S3.BucketArgs
    {
    });
    var queue = new Aws.Sqs.Queue("queue", new Aws.Sqs.QueueArgs
    {
        Policy = bucket.Arn.Apply(arn => @$"{{
""Version"": ""2012-10-17"",
""Statement"": [
{{
  ""Effect"": ""Allow"",
  ""Principal"": ""*"",
  ""Action"": ""sqs:SendMessage"",
""Resource"": ""arn:aws:sqs:*:*:s3-event-notification-queue"",
  ""Condition"": {{
    ""ArnEquals"": {{ ""aws:SourceArn"": ""{arn}"" }}
  }}
}}
]
}}

"),
    });
    var bucketNotification = new Aws.S3.BucketNotification("bucketNotification", new Aws.S3.BucketNotificationArgs
    {
        Bucket = bucket.Id,
        Queues = 
        {
            new Aws.S3.Inputs.BucketNotificationQueueArgs
            {
                Events = 
                {
                    "s3:ObjectCreated:*",
                },
                FilterPrefix = "images/",
                Id = "image-upload-event",
                QueueArn = queue.Arn,
            },
            new Aws.S3.Inputs.BucketNotificationQueueArgs
            {
                Events = 
                {
                    "s3:ObjectCreated:*",
                },
                FilterPrefix = "videos/",
                Id = "video-upload-event",
                QueueArn = queue.Arn,
            },
        },
    });
}

}
Inheritance
System.Object
Resource
CustomResource
BucketNotification
Inherited Members
CustomResource.Id
Resource.GetResourceType()
Resource.GetResourceName()
Resource.Urn
System.Object.Equals(System.Object)
System.Object.Equals(System.Object, System.Object)
System.Object.GetHashCode()
System.Object.GetType()
System.Object.MemberwiseClone()
System.Object.ReferenceEquals(System.Object, System.Object)
System.Object.ToString()
Namespace: Pulumi.Aws.S3
Assembly: Pulumi.Aws.dll
Syntax
public class BucketNotification : CustomResource

Constructors

View Source

BucketNotification(String, BucketNotificationArgs, CustomResourceOptions)

Create a BucketNotification resource with the given unique name, arguments, and options.

Declaration
public BucketNotification(string name, BucketNotificationArgs args, CustomResourceOptions options = null)
Parameters
Type Name Description
System.String name

The unique name of the resource

BucketNotificationArgs args

The arguments used to populate this resource's properties

CustomResourceOptions options

A bag of options that control this resource's behavior

Properties

View Source

Bucket

The name of the bucket to put notification configuration.

Declaration
public Output<string> Bucket { get; }
Property Value
Type Description
Output<System.String>
View Source

LambdaFunctions

Used to configure notifications to a Lambda Function (documented below).

Declaration
public Output<ImmutableArray<BucketNotificationLambdaFunction>> LambdaFunctions { get; }
Property Value
Type Description
Output<System.Collections.Immutable.ImmutableArray<BucketNotificationLambdaFunction>>
View Source

Queues

The notification configuration to SQS Queue (documented below).

Declaration
public Output<ImmutableArray<BucketNotificationQueue>> Queues { get; }
Property Value
Type Description
Output<System.Collections.Immutable.ImmutableArray<BucketNotificationQueue>>
View Source

Topics

The notification configuration to SNS Topic (documented below).

Declaration
public Output<ImmutableArray<BucketNotificationTopic>> Topics { get; }
Property Value
Type Description
Output<System.Collections.Immutable.ImmutableArray<BucketNotificationTopic>>

Methods

View Source

Get(String, Input<String>, BucketNotificationState, CustomResourceOptions)

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

Declaration
public static BucketNotification Get(string name, Input<string> id, BucketNotificationState state = null, CustomResourceOptions options = null)
Parameters
Type Name Description
System.String name

The unique name of the resulting resource.

Input<System.String> id

The unique provider ID of the resource to lookup.

BucketNotificationState state

Any extra arguments used during the lookup.

CustomResourceOptions options

A bag of options that control this resource's behavior

Returns
Type Description
BucketNotification
  • View Source
Back to top Copyright 2016-2020, Pulumi Corporation.