Skip to content

Instantly share code, notes, and snippets.

@100daysofdevops
Created February 14, 2019 23:03
Show Gist options
  • Save 100daysofdevops/fb07c9c4c01ba865b6cc7993cd4eb67e to your computer and use it in GitHub Desktop.
Save 100daysofdevops/fb07c9c4c01ba865b6cc7993cd4eb67e to your computer and use it in GitHub Desktop.
provider "aws" {
region = "us-west-2"
}
resource "aws_sns_topic" "topic" {
name = "s3-event-notification-topic"
policy = <<POLICY
{
"Version":"2012-10-17",
"Statement":[{
"Effect": "Allow",
"Principal": {"AWS":"*"},
"Action": "SNS:Publish",
"Resource": "arn:aws:sns:*:*:s3-event-notification-topic",
"Condition":{
"ArnLike":{"aws:SourceArn":"${aws_s3_bucket.bucket.arn}"}
}
}]
}
POLICY
}
resource "aws_s3_bucket" "bucket" {
bucket = "s3-event-notification-topic-mydemo-bucket"
}
resource "aws_s3_bucket_notification" "bucket_notification" {
bucket = "${aws_s3_bucket.bucket.id}"
topic {
topic_arn = "${aws_sns_topic.topic.arn}"
events = ["s3:ObjectRemoved:*"]
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment