@pulumi/aws
Version:
A Pulumi package for creating and managing Amazon Web Services (AWS) cloud resources.
334 lines • 12 kB
JavaScript
"use strict";
// *** WARNING: this file was generated by pulumi-language-nodejs. ***
// *** Do not edit by hand unless you're certain you know what you are doing! ***
Object.defineProperty(exports, "__esModule", { value: true });
exports.BucketNotification = void 0;
const pulumi = require("@pulumi/pulumi");
const utilities = require("../utilities");
/**
* 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
* ```
*/
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, id, state, opts) {
return new BucketNotification(name, state, { ...opts, id: id });
}
/**
* 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) {
if (obj === undefined || obj === null) {
return false;
}
return obj['__pulumiType'] === BucketNotification.__pulumiType;
}
constructor(name, argsOrState, opts) {
let resourceInputs = {};
opts = opts || {};
if (opts.id) {
const state = argsOrState;
resourceInputs["bucket"] = state?.bucket;
resourceInputs["eventbridge"] = state?.eventbridge;
resourceInputs["lambdaFunctions"] = state?.lambdaFunctions;
resourceInputs["queues"] = state?.queues;
resourceInputs["region"] = state?.region;
resourceInputs["topics"] = state?.topics;
}
else {
const args = argsOrState;
if (args?.bucket === undefined && !opts.urn) {
throw new Error("Missing required property 'bucket'");
}
resourceInputs["bucket"] = args?.bucket;
resourceInputs["eventbridge"] = args?.eventbridge;
resourceInputs["lambdaFunctions"] = args?.lambdaFunctions;
resourceInputs["queues"] = args?.queues;
resourceInputs["region"] = args?.region;
resourceInputs["topics"] = args?.topics;
}
opts = pulumi.mergeOptions(utilities.resourceOptsDefaults(), opts);
super(BucketNotification.__pulumiType, name, resourceInputs, opts);
}
}
exports.BucketNotification = BucketNotification;
/** @internal */
BucketNotification.__pulumiType = 'aws:s3/bucketNotification:BucketNotification';
//# sourceMappingURL=bucketNotification.js.map