Skip to content

Instantly share code, notes, and snippets.

@rselva
Last active November 5, 2024 10:34
Show Gist options
  • Save rselva/ac8e1528a564dc8521cc5be3e59246bc to your computer and use it in GitHub Desktop.
Save rselva/ac8e1528a564dc8521cc5be3e59246bc to your computer and use it in GitHub Desktop.
bucket_with_two_notification
terraform {
required_providers {
aws = {
source = "hashicorp/aws"
version = "5.74.0"
}
}
}
provider "aws" {
region = "us-east-1"
}
resource "aws_s3_bucket" "bucket" {
bucket = "selva-terraform-bucket-1111111111"
}
resource "aws_s3_bucket_notification" "bucket_notification" {
bucket = aws_s3_bucket.bucket.id
eventbridge = true
}
data "aws_iam_policy_document" "topic" {
statement {
effect = "Allow"
principals {
type = "Service"
identifiers = ["s3.amazonaws.com"]
}
actions = ["SNS:Publish"]
resources = ["arn:aws:sns:*:*:s3-event-notification-topic"]
condition {
test = "ArnLike"
variable = "aws:SourceArn"
values = [aws_s3_bucket.bucket.arn]
}
}
}
resource "aws_sns_topic" "topic" {
name = "s3-event-notification-topic"
policy = data.aws_iam_policy_document.topic.json
}
resource "aws_s3_bucket_notification" "sns_notification" {
bucket = aws_s3_bucket.bucket.id
topic {
topic_arn = aws_sns_topic.topic.arn
events = ["s3:ObjectCreated:*"]
filter_suffix = ".log"
}
}
resource "aws_s3_bucket_notification" "eventbridge" {
bucket = aws_s3_bucket.bucket.id
eventbridge = true
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment