@pulumi/aws
Version:
A Pulumi package for creating and managing Amazon Web Services (AWS) cloud resources.
389 lines (388 loc) • 14.1 kB
TypeScript
import * as pulumi from "@pulumi/pulumi";
import * as inputs from "../types/input";
import * as outputs from "../types/output";
/**
* Manages a S3 Bucket Notification Configuration. For additional information, see the [Configuring S3 Event Notifications section in the Amazon S3 Developer Guide](https://docs.aws.amazon.com/AmazonS3/latest/dev/NotificationHowTo.html).
*
* > **NOTE:** S3 Buckets only support a single notification configuration resource. Declaring multiple `aws.s3.BucketNotification` resources to the same S3 Bucket will cause a perpetual difference in configuration. This resource will overwrite any existing event notifications configured for the S3 bucket it's associated with. See the example "Trigger multiple Lambda functions" for an option of how to configure multiple triggers within this resource.
*
* > This resource cannot be used with S3 directory buckets.
*
* ## Example Usage
*
* ### Add notification configuration to SNS Topic
*
* ```typescript
* import * as pulumi from "@pulumi/pulumi";
* import * as aws from "@pulumi/aws";
*
* const bucket = new aws.s3.Bucket("bucket", {bucket: "your-bucket-name"});
* const topic = aws.iam.getPolicyDocumentOutput({
* statements: [{
* effect: "Allow",
* principals: [{
* type: "Service",
* identifiers: ["s3.amazonaws.com"],
* }],
* actions: ["SNS:Publish"],
* resources: ["arn:aws:sns:*:*:s3-event-notification-topic"],
* conditions: [{
* test: "ArnLike",
* variable: "aws:SourceArn",
* values: [bucket.arn],
* }],
* }],
* });
* const topicTopic = new aws.sns.Topic("topic", {
* name: "s3-event-notification-topic",
* policy: topic.apply(topic => topic.json),
* });
* const bucketNotification = new aws.s3.BucketNotification("bucket_notification", {
* bucket: bucket.id,
* topics: [{
* topicArn: topicTopic.arn,
* events: ["s3:ObjectCreated:*"],
* filterSuffix: ".log",
* }],
* });
* ```
*
* ### Add notification configuration to SQS Queue
*
* ```typescript
* import * as pulumi from "@pulumi/pulumi";
* import * as aws from "@pulumi/aws";
*
* const bucket = new aws.s3.Bucket("bucket", {bucket: "your-bucket-name"});
* const queue = aws.iam.getPolicyDocumentOutput({
* statements: [{
* effect: "Allow",
* principals: [{
* type: "*",
* identifiers: ["*"],
* }],
* actions: ["sqs:SendMessage"],
* resources: ["arn:aws:sqs:*:*:s3-event-notification-queue"],
* conditions: [{
* test: "ArnEquals",
* variable: "aws:SourceArn",
* values: [bucket.arn],
* }],
* }],
* });
* const queueQueue = new aws.sqs.Queue("queue", {
* name: "s3-event-notification-queue",
* policy: queue.apply(queue => queue.json),
* });
* const bucketNotification = new aws.s3.BucketNotification("bucket_notification", {
* bucket: bucket.id,
* queues: [{
* queueArn: queueQueue.arn,
* events: ["s3:ObjectCreated:*"],
* filterSuffix: ".log",
* }],
* });
* ```
*
* ### Add notification configuration to Lambda Function
*
* ```typescript
* import * as pulumi from "@pulumi/pulumi";
* import * as aws from "@pulumi/aws";
*
* const assumeRole = aws.iam.getPolicyDocument({
* statements: [{
* effect: "Allow",
* principals: [{
* type: "Service",
* identifiers: ["lambda.amazonaws.com"],
* }],
* actions: ["sts:AssumeRole"],
* }],
* });
* const iamForLambda = new aws.iam.Role("iam_for_lambda", {
* name: "iam_for_lambda",
* assumeRolePolicy: assumeRole.then(assumeRole => assumeRole.json),
* });
* const func = new aws.lambda.Function("func", {
* code: new pulumi.asset.FileArchive("your-function.zip"),
* name: "example_lambda_name",
* role: iamForLambda.arn,
* handler: "exports.example",
* runtime: aws.lambda.Runtime.NodeJS20dX,
* });
* const bucket = new aws.s3.Bucket("bucket", {bucket: "your-bucket-name"});
* const allowBucket = new aws.lambda.Permission("allow_bucket", {
* statementId: "AllowExecutionFromS3Bucket",
* action: "lambda:InvokeFunction",
* "function": func.arn,
* principal: "s3.amazonaws.com",
* sourceArn: bucket.arn,
* });
* const bucketNotification = new aws.s3.BucketNotification("bucket_notification", {
* bucket: bucket.id,
* lambdaFunctions: [{
* lambdaFunctionArn: func.arn,
* events: ["s3:ObjectCreated:*"],
* filterPrefix: "AWSLogs/",
* filterSuffix: ".log",
* }],
* }, {
* dependsOn: [allowBucket],
* });
* ```
*
* ### Trigger multiple Lambda functions
*
* ```typescript
* import * as pulumi from "@pulumi/pulumi";
* import * as aws from "@pulumi/aws";
*
* const assumeRole = aws.iam.getPolicyDocument({
* statements: [{
* effect: "Allow",
* principals: [{
* type: "Service",
* identifiers: ["lambda.amazonaws.com"],
* }],
* actions: ["sts:AssumeRole"],
* }],
* });
* const iamForLambda = new aws.iam.Role("iam_for_lambda", {
* name: "iam_for_lambda",
* assumeRolePolicy: assumeRole.then(assumeRole => assumeRole.json),
* });
* const func1 = new aws.lambda.Function("func1", {
* code: new pulumi.asset.FileArchive("your-function1.zip"),
* name: "example_lambda_name1",
* role: iamForLambda.arn,
* handler: "exports.example",
* runtime: aws.lambda.Runtime.NodeJS20dX,
* });
* const bucket = new aws.s3.Bucket("bucket", {bucket: "your-bucket-name"});
* const allowBucket1 = new aws.lambda.Permission("allow_bucket1", {
* statementId: "AllowExecutionFromS3Bucket1",
* 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"),
* name: "example_lambda_name2",
* role: iamForLambda.arn,
* handler: "exports.example",
* });
* const allowBucket2 = new aws.lambda.Permission("allow_bucket2", {
* statementId: "AllowExecutionFromS3Bucket2",
* action: "lambda:InvokeFunction",
* "function": func2.arn,
* principal: "s3.amazonaws.com",
* sourceArn: bucket.arn,
* });
* const bucketNotification = new aws.s3.BucketNotification("bucket_notification", {
* 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
*
* ```typescript
* import * as pulumi from "@pulumi/pulumi";
* import * as aws from "@pulumi/aws";
*
* const bucket = new aws.s3.Bucket("bucket", {bucket: "your-bucket-name"});
* const queue = aws.iam.getPolicyDocumentOutput({
* statements: [{
* effect: "Allow",
* principals: [{
* type: "*",
* identifiers: ["*"],
* }],
* actions: ["sqs:SendMessage"],
* resources: ["arn:aws:sqs:*:*:s3-event-notification-queue"],
* conditions: [{
* test: "ArnEquals",
* variable: "aws:SourceArn",
* values: [bucket.arn],
* }],
* }],
* });
* const queueQueue = new aws.sqs.Queue("queue", {
* name: "s3-event-notification-queue",
* policy: queue.apply(queue => queue.json),
* });
* const bucketNotification = new aws.s3.BucketNotification("bucket_notification", {
* bucket: bucket.id,
* queues: [
* {
* id: "image-upload-event",
* queueArn: queueQueue.arn,
* events: ["s3:ObjectCreated:*"],
* filterPrefix: "images/",
* },
* {
* id: "video-upload-event",
* queueArn: queueQueue.arn,
* events: ["s3:ObjectCreated:*"],
* filterPrefix: "videos/",
* },
* ],
* });
* ```
*
* For JSON syntax, use an array instead of defining the `queue` key twice.
*
* ### Emit events to EventBridge
*
* ```typescript
* import * as pulumi from "@pulumi/pulumi";
* import * as aws from "@pulumi/aws";
*
* const bucket = new aws.s3.Bucket("bucket", {bucket: "your-bucket-name"});
* const bucketNotification = new aws.s3.BucketNotification("bucket_notification", {
* bucket: bucket.id,
* eventbridge: true,
* });
* ```
*
* ## Import
*
* Using `pulumi import`, import S3 bucket notification using the `bucket`. For example:
*
* ```sh
* $ pulumi import aws:s3/bucketNotification:BucketNotification bucket_notification bucket-name
* ```
*/
export declare class BucketNotification extends pulumi.CustomResource {
/**
* Get an existing BucketNotification resource's state with the given name, ID, and optional extra
* properties used to qualify the lookup.
*
* @param name The _unique_ name of the resulting resource.
* @param id The _unique_ provider ID of the resource to lookup.
* @param state Any extra arguments used during the lookup.
* @param opts Optional settings to control the behavior of the CustomResource.
*/
static get(name: string, id: pulumi.Input<pulumi.ID>, state?: BucketNotificationState, opts?: pulumi.CustomResourceOptions): BucketNotification;
/**
* Returns true if the given object is an instance of BucketNotification. This is designed to work even
* when multiple copies of the Pulumi SDK have been loaded into the same process.
*/
static isInstance(obj: any): obj is BucketNotification;
/**
* Name of the bucket for notification configuration.
*
* The following arguments are optional:
*/
readonly bucket: pulumi.Output<string>;
/**
* Whether to enable Amazon EventBridge notifications. Defaults to `false`.
*/
readonly eventbridge: pulumi.Output<boolean | undefined>;
/**
* Used to configure notifications to a Lambda Function. See below.
*/
readonly lambdaFunctions: pulumi.Output<outputs.s3.BucketNotificationLambdaFunction[] | undefined>;
/**
* Notification configuration to SQS Queue. See below.
*/
readonly queues: pulumi.Output<outputs.s3.BucketNotificationQueue[] | undefined>;
/**
* Region where this resource will be [managed](https://docs.aws.amazon.com/general/latest/gr/rande.html#regional-endpoints). Defaults to the Region set in the provider configuration.
*/
readonly region: pulumi.Output<string>;
/**
* Notification configuration to SNS Topic. See below.
*/
readonly topics: pulumi.Output<outputs.s3.BucketNotificationTopic[] | undefined>;
/**
* Create a BucketNotification resource with the given unique name, arguments, and options.
*
* @param name The _unique_ name of the resource.
* @param args The arguments to use to populate this resource's properties.
* @param opts A bag of options that control this resource's behavior.
*/
constructor(name: string, args: BucketNotificationArgs, opts?: pulumi.CustomResourceOptions);
}
/**
* Input properties used for looking up and filtering BucketNotification resources.
*/
export interface BucketNotificationState {
/**
* Name of the bucket for notification configuration.
*
* The following arguments are optional:
*/
bucket?: pulumi.Input<string>;
/**
* Whether to enable Amazon EventBridge notifications. Defaults to `false`.
*/
eventbridge?: pulumi.Input<boolean>;
/**
* Used to configure notifications to a Lambda Function. See below.
*/
lambdaFunctions?: pulumi.Input<pulumi.Input<inputs.s3.BucketNotificationLambdaFunction>[]>;
/**
* Notification configuration to SQS Queue. See below.
*/
queues?: pulumi.Input<pulumi.Input<inputs.s3.BucketNotificationQueue>[]>;
/**
* Region where this resource will be [managed](https://docs.aws.amazon.com/general/latest/gr/rande.html#regional-endpoints). Defaults to the Region set in the provider configuration.
*/
region?: pulumi.Input<string>;
/**
* Notification configuration to SNS Topic. See below.
*/
topics?: pulumi.Input<pulumi.Input<inputs.s3.BucketNotificationTopic>[]>;
}
/**
* The set of arguments for constructing a BucketNotification resource.
*/
export interface BucketNotificationArgs {
/**
* Name of the bucket for notification configuration.
*
* The following arguments are optional:
*/
bucket: pulumi.Input<string>;
/**
* Whether to enable Amazon EventBridge notifications. Defaults to `false`.
*/
eventbridge?: pulumi.Input<boolean>;
/**
* Used to configure notifications to a Lambda Function. See below.
*/
lambdaFunctions?: pulumi.Input<pulumi.Input<inputs.s3.BucketNotificationLambdaFunction>[]>;
/**
* Notification configuration to SQS Queue. See below.
*/
queues?: pulumi.Input<pulumi.Input<inputs.s3.BucketNotificationQueue>[]>;
/**
* Region where this resource will be [managed](https://docs.aws.amazon.com/general/latest/gr/rande.html#regional-endpoints). Defaults to the Region set in the provider configuration.
*/
region?: pulumi.Input<string>;
/**
* Notification configuration to SNS Topic. See below.
*/
topics?: pulumi.Input<pulumi.Input<inputs.s3.BucketNotificationTopic>[]>;
}