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,
                },
            },
        });
    }

}
package main

import (
    "fmt"

    "github.com/pulumi/pulumi-aws/sdk/v2/go/aws/s3"
    "github.com/pulumi/pulumi-aws/sdk/v2/go/aws/sns"
    "github.com/pulumi/pulumi/sdk/v2/go/pulumi"
)

func main() {
    pulumi.Run(func(ctx *pulumi.Context) error {
        bucket, err := s3.NewBucket(ctx, "bucket", nil)
        if err != nil {
            return err
        }
        topic, err := sns.NewTopic(ctx, "topic", &sns.TopicArgs{
            Policy: bucket.Arn.ApplyT(func(arn string) (string, error) {
                return fmt.Sprintf("%v%v%v%v%v%v%v%v%v%v%v%v%v%v%v", "{\n", "    \"Version\":\"2012-10-17\",\n", "    \"Statement\":[{\n", "        \"Effect\": \"Allow\",\n", "        \"Principal\": {\"AWS\":\"*\"},\n", "        \"Action\": \"SNS:Publish\",\n", "        \"Resource\": \"arn:aws:sns:*:*:s3-event-notification-topic\",\n", "        \"Condition\":{\n", "            \"ArnLike\":{\"aws:SourceArn\":\"", arn, "\"}\n", "        }\n", "    }]\n", "}\n", "\n"), nil
            }).(pulumi.StringOutput),
        })
        if err != nil {
            return err
        }
        _, err = s3.NewBucketNotification(ctx, "bucketNotification", &s3.BucketNotificationArgs{
            Bucket: bucket.ID(),
            Topics: s3.BucketNotificationTopicArray{
                &s3.BucketNotificationTopicArgs{
                    Events: pulumi.StringArray{
                        pulumi.String("s3:ObjectCreated:*"),
                    },
                    FilterSuffix: pulumi.String(".log"),
                    TopicArn:     topic.Arn,
                },
            },
        })
        if err != nil {
            return err
        }
        return nil
    })
}
import pulumi
import pulumi_aws as aws

bucket = aws.s3.Bucket("bucket")
topic = aws.sns.Topic("topic", policy=bucket.arn.apply(lambda arn: f"""{{
    "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}"}}
        }}
    }}]
}}

"""))
bucket_notification = aws.s3.BucketNotification("bucketNotification",
    bucket=bucket.id,
    topics=[{
        "events": ["s3:ObjectCreated:*"],
        "filterSuffix": ".log",
        "topic_arn": topic.arn,
    }])
import * as pulumi from "@pulumi/pulumi";
import * as aws from "@pulumi/aws";

const bucket = new aws.s3.Bucket("bucket", {});
const topic = new aws.sns.Topic("topic", {
    policy: pulumi.interpolate`{
    "Version":"2012-10-17",
    "Statement":[{
        "Effect": "Allow",
        "Principal": {"AWS":"*"},
        "Action": "SNS:Publish",
        "Resource": "arn:aws:sns:*:*:s3-event-notification-topic",
        "Condition":{
            "ArnLike":{"aws:SourceArn":"${bucket.arn}"}
        }
    }]
}
`,
});
const bucketNotification = new aws.s3.BucketNotification("bucket_notification", {
    bucket: bucket.id,
    topics: [{
        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,
                },
            },
        });
    }

}
package main

import (
    "fmt"

    "github.com/pulumi/pulumi-aws/sdk/v2/go/aws/s3"
    "github.com/pulumi/pulumi-aws/sdk/v2/go/aws/sqs"
    "github.com/pulumi/pulumi/sdk/v2/go/pulumi"
)

func main() {
    pulumi.Run(func(ctx *pulumi.Context) error {
        bucket, err := s3.NewBucket(ctx, "bucket", nil)
        if err != nil {
            return err
        }
        queue, err := sqs.NewQueue(ctx, "queue", &sqs.QueueArgs{
            Policy: bucket.Arn.ApplyT(func(arn string) (string, error) {
                return fmt.Sprintf("%v%v%v%v%v%v%v%v%v%v%v%v%v%v%v%v%v", "{\n", "  \"Version\": \"2012-10-17\",\n", "  \"Statement\": [\n", "    {\n", "      \"Effect\": \"Allow\",\n", "      \"Principal\": \"*\",\n", "      \"Action\": \"sqs:SendMessage\",\n", "      \"Resource\": \"arn:aws:sqs:*:*:s3-event-notification-queue\",\n", "      \"Condition\": {\n", "        \"ArnEquals\": { \"aws:SourceArn\": \"", arn, "\" }\n", "      }\n", "    }\n", "  ]\n", "}\n", "\n"), nil
            }).(pulumi.StringOutput),
        })
        if err != nil {
            return err
        }
        _, err = s3.NewBucketNotification(ctx, "bucketNotification", &s3.BucketNotificationArgs{
            Bucket: bucket.ID(),
            Queues: s3.BucketNotificationQueueArray{
                &s3.BucketNotificationQueueArgs{
                    Events: pulumi.StringArray{
                        pulumi.String("s3:ObjectCreated:*"),
                    },
                    FilterSuffix: pulumi.String(".log"),
                    QueueArn:     queue.Arn,
                },
            },
        })
        if err != nil {
            return err
        }
        return nil
    })
}
import pulumi
import pulumi_aws as aws

bucket = aws.s3.Bucket("bucket")
queue = aws.sqs.Queue("queue", policy=bucket.arn.apply(lambda arn: f"""{{
  "Version": "2012-10-17",
  "Statement": [
    {{
      "Effect": "Allow",
      "Principal": "*",
      "Action": "sqs:SendMessage",
      "Resource": "arn:aws:sqs:*:*:s3-event-notification-queue",
      "Condition": {{
        "ArnEquals": {{ "aws:SourceArn": "{arn}" }}
      }}
    }}
  ]
}}

"""))
bucket_notification = aws.s3.BucketNotification("bucketNotification",
    bucket=bucket.id,
    queues=[{
        "events": ["s3:ObjectCreated:*"],
        "filterSuffix": ".log",
        "queueArn": queue.arn,
    }])
import * as pulumi from "@pulumi/pulumi";
import * as aws from "@pulumi/aws";

const bucket = new aws.s3.Bucket("bucket", {});
const queue = new aws.sqs.Queue("queue", {
    policy: pulumi.interpolate`{
  "Version": "2012-10-17",
  "Statement": [
    {
      "Effect": "Allow",
      "Principal": "*",
      "Action": "sqs:SendMessage",
      "Resource": "arn:aws:sqs:*:*:s3-event-notification-queue",
      "Condition": {
        "ArnEquals": { "aws:SourceArn": "${bucket.arn}" }
      }
    }
  ]
}
`,
});
const bucketNotification = new aws.s3.BucketNotification("bucket_notification", {
    bucket: bucket.id,
    queues: [{
        events: ["s3:ObjectCreated:*"],
        filterSuffix: ".log",
        queueArn: queue.arn,
    }],
});

Add notification configuration to Lambda Function

using Pulumi;
using Aws = Pulumi.Aws;

class MyStack : Stack
{
    public MyStack()
    {
        var iamForLambda = new Aws.Iam.Role("iamForLambda", new Aws.Iam.RoleArgs
        {
            AssumeRolePolicy = @"{
  ""Version"": ""2012-10-17"",
  ""Statement"": [
    {
      ""Action"": ""sts:AssumeRole"",
      ""Principal"": {
        ""Service"": ""lambda.amazonaws.com""
      },
      ""Effect"": ""Allow""
    }
  ]
}
",
        });
        var func = new Aws.Lambda.Function("func", new Aws.Lambda.FunctionArgs
        {
            Code = new FileArchive("your-function.zip"),
            Role = iamForLambda.Arn,
            Handler = "exports.example",
            Runtime = "go1.x",
        });
        var bucket = new Aws.S3.Bucket("bucket", new Aws.S3.BucketArgs
        {
        });
        var allowBucket = new Aws.Lambda.Permission("allowBucket", new Aws.Lambda.PermissionArgs
        {
            Action = "lambda:InvokeFunction",
            Function = func.Arn,
            Principal = "s3.amazonaws.com",
            SourceArn = bucket.Arn,
        });
        var bucketNotification = new Aws.S3.BucketNotification("bucketNotification", new Aws.S3.BucketNotificationArgs
        {
            Bucket = bucket.Id,
            LambdaFunctions = 
            {
                new Aws.S3.Inputs.BucketNotificationLambdaFunctionArgs
                {
                    LambdaFunctionArn = func.Arn,
                    Events = 
                    {
                        "s3:ObjectCreated:*",
                    },
                    FilterPrefix = "AWSLogs/",
                    FilterSuffix = ".log",
                },
            },
        }, new CustomResourceOptions
        {
            DependsOn = 
            {
                allowBucket,
            },
        });
    }

}

Coming soon!

import pulumi
import pulumi_aws as aws

iam_for_lambda = aws.iam.Role("iamForLambda", assume_role_policy="""{
  "Version": "2012-10-17",
  "Statement": [
    {
      "Action": "sts:AssumeRole",
      "Principal": {
        "Service": "lambda.amazonaws.com"
      },
      "Effect": "Allow"
    }
  ]
}
""")
func = aws.lambda_.Function("func",
    code=pulumi.FileArchive("your-function.zip"),
    role=iam_for_lambda.arn,
    handler="exports.example",
    runtime="go1.x")
bucket = aws.s3.Bucket("bucket")
allow_bucket = aws.lambda_.Permission("allowBucket",
    action="lambda:InvokeFunction",
    function=func.arn,
    principal="s3.amazonaws.com",
    source_arn=bucket.arn)
bucket_notification = aws.s3.BucketNotification("bucketNotification",
    bucket=bucket.id,
    lambda_functions=[{
        "lambda_function_arn": func.arn,
        "events": ["s3:ObjectCreated:*"],
        "filterPrefix": "AWSLogs/",
        "filterSuffix": ".log",
    }],
    opts=ResourceOptions(depends_on=[allow_bucket]))
import * as pulumi from "@pulumi/pulumi";
import * as aws from "@pulumi/aws";

const iamForLambda = new aws.iam.Role("iamForLambda", {assumeRolePolicy: `{
  "Version": "2012-10-17",
  "Statement": [
    {
      "Action": "sts:AssumeRole",
      "Principal": {
        "Service": "lambda.amazonaws.com"
      },
      "Effect": "Allow"
    }
  ]
}
`});
const func = new aws.lambda.Function("func", {
    code: new pulumi.asset.FileArchive("your-function.zip"),
    role: iamForLambda.arn,
    handler: "exports.example",
    runtime: "go1.x",
});
const bucket = new aws.s3.Bucket("bucket", {});
const allowBucket = new aws.lambda.Permission("allowBucket", {
    action: "lambda:InvokeFunction",
    "function": func.arn,
    principal: "s3.amazonaws.com",
    sourceArn: bucket.arn,
});
const bucketNotification = new aws.s3.BucketNotification("bucketNotification", {
    bucket: bucket.id,
    lambdaFunctions: [{
        lambdaFunctionArn: func.arn,
        events: ["s3:ObjectCreated:*"],
        filterPrefix: "AWSLogs/",
        filterSuffix: ".log",
    }],
}, {
    dependsOn: [allowBucket],
});

Trigger multiple Lambda functions

using Pulumi;
using Aws = Pulumi.Aws;

class MyStack : Stack
{
    public MyStack()
    {
        var iamForLambda = new Aws.Iam.Role("iamForLambda", new Aws.Iam.RoleArgs
        {
            AssumeRolePolicy = @"{
  ""Version"": ""2012-10-17"",
  ""Statement"": [
    {
      ""Action"": ""sts:AssumeRole"",
      ""Principal"": {
        ""Service"": ""lambda.amazonaws.com""
      },
      ""Effect"": ""Allow""
    }
  ]
}
",
        });
        var func1 = new Aws.Lambda.Function("func1", new Aws.Lambda.FunctionArgs
        {
            Code = new FileArchive("your-function1.zip"),
            Role = iamForLambda.Arn,
            Handler = "exports.example",
            Runtime = "go1.x",
        });
        var bucket = new Aws.S3.Bucket("bucket", new Aws.S3.BucketArgs
        {
        });
        var allowBucket1 = new Aws.Lambda.Permission("allowBucket1", new Aws.Lambda.PermissionArgs
        {
            Action = "lambda:InvokeFunction",
            Function = func1.Arn,
            Principal = "s3.amazonaws.com",
            SourceArn = bucket.Arn,
        });
        var func2 = new Aws.Lambda.Function("func2", new Aws.Lambda.FunctionArgs
        {
            Code = new FileArchive("your-function2.zip"),
            Role = iamForLambda.Arn,
            Handler = "exports.example",
        });
        var allowBucket2 = new Aws.Lambda.Permission("allowBucket2", new Aws.Lambda.PermissionArgs
        {
            Action = "lambda:InvokeFunction",
            Function = func2.Arn,
            Principal = "s3.amazonaws.com",
            SourceArn = bucket.Arn,
        });
        var bucketNotification = new Aws.S3.BucketNotification("bucketNotification", new Aws.S3.BucketNotificationArgs
        {
            Bucket = bucket.Id,
            LambdaFunctions = 
            {
                new Aws.S3.Inputs.BucketNotificationLambdaFunctionArgs
                {
                    LambdaFunctionArn = func1.Arn,
                    Events = 
                    {
                        "s3:ObjectCreated:*",
                    },
                    FilterPrefix = "AWSLogs/",
                    FilterSuffix = ".log",
                },
                new Aws.S3.Inputs.BucketNotificationLambdaFunctionArgs
                {
                    LambdaFunctionArn = func2.Arn,
                    Events = 
                    {
                        "s3:ObjectCreated:*",
                    },
                    FilterPrefix = "OtherLogs/",
                    FilterSuffix = ".log",
                },
            },
        }, new CustomResourceOptions
        {
            DependsOn = 
            {
                allowBucket1,
                allowBucket2,
            },
        });
    }

}

Coming soon!

import pulumi
import pulumi_aws as aws

iam_for_lambda = aws.iam.Role("iamForLambda", assume_role_policy="""{
  "Version": "2012-10-17",
  "Statement": [
    {
      "Action": "sts:AssumeRole",
      "Principal": {
        "Service": "lambda.amazonaws.com"
      },
      "Effect": "Allow"
    }
  ]
}
""")
func1 = aws.lambda_.Function("func1",
    code=pulumi.FileArchive("your-function1.zip"),
    role=iam_for_lambda.arn,
    handler="exports.example",
    runtime="go1.x")
bucket = aws.s3.Bucket("bucket")
allow_bucket1 = aws.lambda_.Permission("allowBucket1",
    action="lambda:InvokeFunction",
    function=func1.arn,
    principal="s3.amazonaws.com",
    source_arn=bucket.arn)
func2 = aws.lambda_.Function("func2",
    code=pulumi.FileArchive("your-function2.zip"),
    role=iam_for_lambda.arn,
    handler="exports.example")
allow_bucket2 = aws.lambda_.Permission("allowBucket2",
    action="lambda:InvokeFunction",
    function=func2.arn,
    principal="s3.amazonaws.com",
    source_arn=bucket.arn)
bucket_notification = aws.s3.BucketNotification("bucketNotification",
    bucket=bucket.id,
    lambda_functions=[
        {
            "lambda_function_arn": func1.arn,
            "events": ["s3:ObjectCreated:*"],
            "filterPrefix": "AWSLogs/",
            "filterSuffix": ".log",
        },
        {
            "lambda_function_arn": func2.arn,
            "events": ["s3:ObjectCreated:*"],
            "filterPrefix": "OtherLogs/",
            "filterSuffix": ".log",
        },
    ],
    opts=ResourceOptions(depends_on=[
            allow_bucket1,
            allow_bucket2,
        ]))
import * as pulumi from "@pulumi/pulumi";
import * as aws from "@pulumi/aws";

const iamForLambda = new aws.iam.Role("iamForLambda", {assumeRolePolicy: `{
  "Version": "2012-10-17",
  "Statement": [
    {
      "Action": "sts:AssumeRole",
      "Principal": {
        "Service": "lambda.amazonaws.com"
      },
      "Effect": "Allow"
    }
  ]
}
`});
const func1 = new aws.lambda.Function("func1", {
    code: new pulumi.asset.FileArchive("your-function1.zip"),
    role: iamForLambda.arn,
    handler: "exports.example",
    runtime: "go1.x",
});
const bucket = new aws.s3.Bucket("bucket", {});
const allowBucket1 = new aws.lambda.Permission("allowBucket1", {
    action: "lambda:InvokeFunction",
    "function": func1.arn,
    principal: "s3.amazonaws.com",
    sourceArn: bucket.arn,
});
const func2 = new aws.lambda.Function("func2", {
    code: new pulumi.asset.FileArchive("your-function2.zip"),
    role: iamForLambda.arn,
    handler: "exports.example",
});
const allowBucket2 = new aws.lambda.Permission("allowBucket2", {
    action: "lambda:InvokeFunction",
    "function": func2.arn,
    principal: "s3.amazonaws.com",
    sourceArn: bucket.arn,
});
const bucketNotification = new aws.s3.BucketNotification("bucketNotification", {
    bucket: bucket.id,
    lambdaFunctions: [
        {
            lambdaFunctionArn: func1.arn,
            events: ["s3:ObjectCreated:*"],
            filterPrefix: "AWSLogs/",
            filterSuffix: ".log",
        },
        {
            lambdaFunctionArn: func2.arn,
            events: ["s3:ObjectCreated:*"],
            filterPrefix: "OtherLogs/",
            filterSuffix: ".log",
        },
    ],
}, {
    dependsOn: [
        allowBucket1,
        allowBucket2,
    ],
});

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,
                },
            },
        });
    }

}
package main

import (
    "fmt"

    "github.com/pulumi/pulumi-aws/sdk/v2/go/aws/s3"
    "github.com/pulumi/pulumi-aws/sdk/v2/go/aws/sqs"
    "github.com/pulumi/pulumi/sdk/v2/go/pulumi"
)

func main() {
    pulumi.Run(func(ctx *pulumi.Context) error {
        bucket, err := s3.NewBucket(ctx, "bucket", nil)
        if err != nil {
            return err
        }
        queue, err := sqs.NewQueue(ctx, "queue", &sqs.QueueArgs{
            Policy: bucket.Arn.ApplyT(func(arn string) (string, error) {
                return fmt.Sprintf("%v%v%v%v%v%v%v%v%v%v%v%v%v%v%v%v%v", "{\n", "  \"Version\": \"2012-10-17\",\n", "  \"Statement\": [\n", "    {\n", "      \"Effect\": \"Allow\",\n", "      \"Principal\": \"*\",\n", "      \"Action\": \"sqs:SendMessage\",\n", "      \"Resource\": \"arn:aws:sqs:*:*:s3-event-notification-queue\",\n", "      \"Condition\": {\n", "        \"ArnEquals\": { \"aws:SourceArn\": \"", arn, "\" }\n", "      }\n", "    }\n", "  ]\n", "}\n", "\n"), nil
            }).(pulumi.StringOutput),
        })
        if err != nil {
            return err
        }
        _, err = s3.NewBucketNotification(ctx, "bucketNotification", &s3.BucketNotificationArgs{
            Bucket: bucket.ID(),
            Queues: s3.BucketNotificationQueueArray{
                &s3.BucketNotificationQueueArgs{
                    Events: pulumi.StringArray{
                        pulumi.String("s3:ObjectCreated:*"),
                    },
                    FilterPrefix: pulumi.String("images/"),
                    Id:           pulumi.String("image-upload-event"),
                    QueueArn:     queue.Arn,
                },
                &s3.BucketNotificationQueueArgs{
                    Events: pulumi.StringArray{
                        pulumi.String("s3:ObjectCreated:*"),
                    },
                    FilterPrefix: pulumi.String("videos/"),
                    Id:           pulumi.String("video-upload-event"),
                    QueueArn:     queue.Arn,
                },
            },
        })
        if err != nil {
            return err
        }
        return nil
    })
}
import pulumi
import pulumi_aws as aws

bucket = aws.s3.Bucket("bucket")
queue = aws.sqs.Queue("queue", policy=bucket.arn.apply(lambda arn: f"""{{
  "Version": "2012-10-17",
  "Statement": [
    {{
      "Effect": "Allow",
      "Principal": "*",
      "Action": "sqs:SendMessage",
      "Resource": "arn:aws:sqs:*:*:s3-event-notification-queue",
      "Condition": {{
        "ArnEquals": {{ "aws:SourceArn": "{arn}" }}
      }}
    }}
  ]
}}

"""))
bucket_notification = aws.s3.BucketNotification("bucketNotification",
    bucket=bucket.id,
    queues=[
        {
            "events": ["s3:ObjectCreated:*"],
            "filterPrefix": "images/",
            "id": "image-upload-event",
            "queueArn": queue.arn,
        },
        {
            "events": ["s3:ObjectCreated:*"],
            "filterPrefix": "videos/",
            "id": "video-upload-event",
            "queueArn": queue.arn,
        },
    ])
import * as pulumi from "@pulumi/pulumi";
import * as aws from "@pulumi/aws";

const bucket = new aws.s3.Bucket("bucket", {});
const queue = new aws.sqs.Queue("queue", {
    policy: pulumi.interpolate`{
  "Version": "2012-10-17",
  "Statement": [
    {
      "Effect": "Allow",
      "Principal": "*",
      "Action": "sqs:SendMessage",
      "Resource": "arn:aws:sqs:*:*:s3-event-notification-queue",
      "Condition": {
        "ArnEquals": { "aws:SourceArn": "${bucket.arn}" }
      }
    }
  ]
}
`,
});
const bucketNotification = new aws.s3.BucketNotification("bucket_notification", {
    bucket: bucket.id,
    queues: [
        {
            events: ["s3:ObjectCreated:*"],
            filterPrefix: "images/",
            id: "image-upload-event",
            queueArn: queue.arn,
        },
        {
            events: ["s3:ObjectCreated:*"],
            filterPrefix: "videos/",
            id: "video-upload-event",
            queueArn: queue.arn,
        },
    ],
});

Create a BucketNotification Resource

def BucketNotification(resource_name, opts=None, bucket=None, lambda_functions=None, queues=None, topics=None, __props__=None);
name string
The unique name of the resource.
args BucketNotificationArgs
The arguments to resource properties.
opts CustomResourceOptions
Bag of options to control resource's behavior.
resource_name str
The unique name of the resource.
opts ResourceOptions
A bag of options that control this resource's behavior.
ctx Context
Context object for the current deployment.
name string
The unique name of the resource.
args BucketNotificationArgs
The arguments to resource properties.
opts ResourceOption
Bag of options to control resource's behavior.
name string
The unique name of the resource.
args BucketNotificationArgs
The arguments to resource properties.
opts CustomResourceOptions
Bag of options to control resource's behavior.

BucketNotification Resource Properties

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

Inputs

The BucketNotification resource accepts the following input properties:

Bucket string

The name of the bucket to put notification configuration.

LambdaFunctions List<BucketNotificationLambdaFunctionArgs>

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

Queues List<BucketNotificationQueueArgs>

The notification configuration to SQS Queue (documented below).

Topics List<BucketNotificationTopicArgs>

The notification configuration to SNS Topic (documented below).

Bucket string

The name of the bucket to put notification configuration.

LambdaFunctions []BucketNotificationLambdaFunction

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

Queues []BucketNotificationQueue

The notification configuration to SQS Queue (documented below).

Topics []BucketNotificationTopic

The notification configuration to SNS Topic (documented below).

bucket string

The name of the bucket to put notification configuration.

lambdaFunctions BucketNotificationLambdaFunction[]

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

queues BucketNotificationQueue[]

The notification configuration to SQS Queue (documented below).

topics BucketNotificationTopic[]

The notification configuration to SNS Topic (documented below).

bucket str

The name of the bucket to put notification configuration.

lambda_functions List[BucketNotificationLambdaFunction]

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

queues List[BucketNotificationQueue]

The notification configuration to SQS Queue (documented below).

topics List[BucketNotificationTopic]

The notification configuration to SNS Topic (documented below).

Outputs

All input properties are implicitly available as output properties. Additionally, the BucketNotification 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 str
The provider-assigned unique ID for this managed resource.

Look up an Existing BucketNotification Resource

Get an existing BucketNotification 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?: BucketNotificationState, opts?: CustomResourceOptions): BucketNotification
static get(resource_name, id, opts=None, bucket=None, lambda_functions=None, queues=None, topics=None, __props__=None);
func GetBucketNotification(ctx *Context, name string, id IDInput, state *BucketNotificationState, opts ...ResourceOption) (*BucketNotification, error)
public static BucketNotification Get(string name, Input<string> id, BucketNotificationState? state, CustomResourceOptions? opts = null)
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.

The following state arguments are supported:

Bucket string

The name of the bucket to put notification configuration.

LambdaFunctions List<BucketNotificationLambdaFunctionArgs>

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

Queues List<BucketNotificationQueueArgs>

The notification configuration to SQS Queue (documented below).

Topics List<BucketNotificationTopicArgs>

The notification configuration to SNS Topic (documented below).

Bucket string

The name of the bucket to put notification configuration.

LambdaFunctions []BucketNotificationLambdaFunction

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

Queues []BucketNotificationQueue

The notification configuration to SQS Queue (documented below).

Topics []BucketNotificationTopic

The notification configuration to SNS Topic (documented below).

bucket string

The name of the bucket to put notification configuration.

lambdaFunctions BucketNotificationLambdaFunction[]

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

queues BucketNotificationQueue[]

The notification configuration to SQS Queue (documented below).

topics BucketNotificationTopic[]

The notification configuration to SNS Topic (documented below).

bucket str

The name of the bucket to put notification configuration.

lambda_functions List[BucketNotificationLambdaFunction]

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

queues List[BucketNotificationQueue]

The notification configuration to SQS Queue (documented below).

topics List[BucketNotificationTopic]

The notification configuration to SNS Topic (documented below).

Supporting Types

BucketNotificationLambdaFunction

See the input and output API doc for this type.

See the input and output API doc for this type.

See the input and output API doc for this type.

Events List<string>

Specifies event for which to send notifications.

FilterPrefix string

Specifies object key name prefix.

FilterSuffix string

Specifies object key name suffix.

Id string

Specifies unique identifier for each of the notification configurations.

LambdaFunctionArn string

Specifies Amazon Lambda function ARN.

Events []string

Specifies event for which to send notifications.

FilterPrefix string

Specifies object key name prefix.

FilterSuffix string

Specifies object key name suffix.

Id string

Specifies unique identifier for each of the notification configurations.

LambdaFunctionArn string

Specifies Amazon Lambda function ARN.

events string[]

Specifies event for which to send notifications.

filterPrefix string

Specifies object key name prefix.

filterSuffix string

Specifies object key name suffix.

id string

Specifies unique identifier for each of the notification configurations.

lambdaFunctionArn string

Specifies Amazon Lambda function ARN.

events List[str]

Specifies event for which to send notifications.

filterPrefix str

Specifies object key name prefix.

filterSuffix str

Specifies object key name suffix.

id str

Specifies unique identifier for each of the notification configurations.

lambda_function_arn str

Specifies Amazon Lambda function ARN.

BucketNotificationQueue

See the input and output API doc for this type.

See the input and output API doc for this type.

See the input and output API doc for this type.

Events List<string>

Specifies event for which to send notifications.

QueueArn string

Specifies Amazon SQS queue ARN.

FilterPrefix string

Specifies object key name prefix.

FilterSuffix string

Specifies object key name suffix.

Id string

Specifies unique identifier for each of the notification configurations.

Events []string

Specifies event for which to send notifications.

QueueArn string

Specifies Amazon SQS queue ARN.

FilterPrefix string

Specifies object key name prefix.

FilterSuffix string

Specifies object key name suffix.

Id string

Specifies unique identifier for each of the notification configurations.

events string[]

Specifies event for which to send notifications.

queueArn string

Specifies Amazon SQS queue ARN.

filterPrefix string

Specifies object key name prefix.

filterSuffix string

Specifies object key name suffix.

id string

Specifies unique identifier for each of the notification configurations.

events List[str]

Specifies event for which to send notifications.

queueArn str

Specifies Amazon SQS queue ARN.

filterPrefix str

Specifies object key name prefix.

filterSuffix str

Specifies object key name suffix.

id str

Specifies unique identifier for each of the notification configurations.

BucketNotificationTopic

See the input and output API doc for this type.

See the input and output API doc for this type.

See the input and output API doc for this type.

Events List<string>

Specifies event for which to send notifications.

TopicArn string

Specifies Amazon SNS topic ARN.

FilterPrefix string

Specifies object key name prefix.

FilterSuffix string

Specifies object key name suffix.

Id string

Specifies unique identifier for each of the notification configurations.

Events []string

Specifies event for which to send notifications.

TopicArn string

Specifies Amazon SNS topic ARN.

FilterPrefix string

Specifies object key name prefix.

FilterSuffix string

Specifies object key name suffix.

Id string

Specifies unique identifier for each of the notification configurations.

events string[]

Specifies event for which to send notifications.

topicArn string

Specifies Amazon SNS topic ARN.

filterPrefix string

Specifies object key name prefix.

filterSuffix string

Specifies object key name suffix.

id string

Specifies unique identifier for each of the notification configurations.

events List[str]

Specifies event for which to send notifications.

topic_arn str

Specifies Amazon SNS topic ARN.

filterPrefix str

Specifies object key name prefix.

filterSuffix str

Specifies object key name suffix.

id str

Specifies unique identifier for each of the notification configurations.

Package Details

Repository
https://github.com/pulumi/pulumi-aws
License
Apache-2.0
Notes
This Pulumi package is based on the aws Terraform Provider.