github.com/andresvia/terraform@v0.6.15-0.20160412045437-d51c75946785/website/source/docs/providers/aws/r/s3_bucket_notification.html.markdown (about)

     1  ---
     2  layout: "aws"
     3  page_title: "AWS: aws_s3_bucket_notification"
     4  side_bar_current: "docs-aws-resource-s3-bucket-notification"
     5  description: |-
     6    Provides a S3 bucket notification resource.
     7  ---
     8  
     9  # aws\_s3\_bucket\_notification
    10  
    11  Provides a S3 bucket notification resource.
    12  
    13  ## Example Usage
    14  
    15  ### Add notification configuration to SNS Topic
    16  
    17  ```
    18  resource "aws_sns_topic" "topic" {
    19      name = "s3-event-notification-topic"
    20      policy = <<POLICY
    21  {
    22      "Version":"2012-10-17",
    23      "Statement":[{
    24          "Effect": "Allow",
    25          "Principal": {"AWS":"*"},
    26          "Action": "SNS:Publish",
    27          "Resource": "arn:aws:sns:*:*:s3-event-notification-topic",
    28          "Condition":{
    29              "ArnLike":{"aws:SourceArn":"${aws_s3_bucket.bucket.arn}"}
    30          }
    31      }]
    32  }
    33  POLICY
    34  }
    35  
    36  resource "aws_s3_bucket" "bucket" {
    37  	bucket = "your_bucket_name"
    38  }
    39  
    40  resource "aws_s3_bucket_notification" "bucket_notification" {
    41  	bucket = "${aws_s3_bucket.bucket.id}"
    42  	topic {
    43  		topic_arn = "${aws_sns_topic.topic.arn}"
    44  		events = ["s3:ObjectCreated:*"]
    45  		filter_suffix = ".log"
    46  	}
    47  }
    48  ```
    49  
    50  ### Add notification configuration to SQS Queue
    51  
    52  ```
    53  resource "aws_sqs_queue" "queue" {
    54      name = "s3-event-notification-queue"
    55      policy = <<POLICY
    56  {
    57    "Version": "2012-10-17",
    58    "Statement": [
    59      {
    60        "Effect": "Allow",
    61        "Principal": "*",
    62        "Action": "sqs:SendMessage",
    63  	  "Resource": "arn:aws:sqs:*:*:s3-event-notification-queue",
    64        "Condition": {
    65          "ArnEquals": { "aws:SourceArn": "${aws_s3_bucket.bucket.arn}" }
    66        }
    67      }
    68    ]
    69  }
    70  POLICY
    71  }
    72  
    73  resource "aws_s3_bucket" "bucket" {
    74  	bucket = "your_bucket_name"
    75  }
    76  
    77  resource "aws_s3_bucket_notification" "bucket_notification" {
    78  	bucket = "${aws_s3_bucket.bucket.id}"
    79  	queue {
    80  		queue_arn = "${aws_sqs_queue.queue.arn}"
    81  		events = ["s3:ObjectCreated:*"]
    82  		filter_suffix = ".log"
    83  	}
    84  }
    85  ```
    86  
    87  ### Add notification configuration to Lambda Function
    88  
    89  ```
    90  resource "aws_iam_role" "iam_for_lambda" {
    91      name = "iam_for_lambda"
    92      assume_role_policy = <<EOF
    93  {
    94    "Version": "2012-10-17",
    95    "Statement": [
    96      {
    97        "Action": "sts:AssumeRole",
    98        "Principal": {
    99          "Service": "lambda.amazonaws.com"
   100        },
   101        "Effect": "Allow"
   102      }
   103    ]
   104  }
   105  EOF
   106  }
   107  
   108  resource "aws_lambda_permission" "allow_bucket" {
   109      statement_id = "AllowExecutionFromS3Bucket"
   110      action = "lambda:InvokeFunction"
   111      function_name = "${aws_lambda_function.func.arn}"
   112      principal = "s3.amazonaws.com"
   113      source_arn = "${aws_s3_bucket.bucket.arn}"
   114  }
   115  
   116  resource "aws_lambda_function" "func" {
   117      filename = "your-function.zip"
   118      function_name = "example_lambda_name"
   119      role = "${aws_iam_role.iam_for_lambda.arn}"
   120      handler = "exports.example"
   121  }
   122  
   123  resource "aws_s3_bucket" "bucket" {
   124  	bucket = "your_bucket_name"
   125  }
   126  
   127  resource "aws_s3_bucket_notification" "bucket_notification" {
   128  	bucket = "${aws_s3_bucket.bucket.id}"
   129  	lambda_function {
   130  		lambda_function_arn = "${aws_lambda_function.func.arn}"
   131  		events = ["s3:ObjectCreated:*"]
   132  		filter_prefix = "AWSLogs/"
   133  		filter_suffix = ".log"
   134  	}
   135  }
   136  ```
   137  
   138  ## Argument Reference
   139  
   140  The following arguments are supported:
   141  
   142  * `bucket` - (Required) The name of the bucket to put notification configuration.
   143  * `topic` - (Optional) The notification configuration to SNS Topic (documented below).
   144  * `queue` - (Optional) The notification configuration to SQS Queue (documented below).
   145  * `lambda_function` - (Optional) The notification configuration to Lambda Function (documented below).
   146  
   147  The `topic` notification configuration supports the following:
   148  
   149  * `id` - (Optional) Specifies unique identifier for each of the notification configurations.
   150  * `topic_arn` - (Required) Specifies Amazon SNS topic ARN.
   151  * `events` - (Required) Specifies [event](http://docs.aws.amazon.com/AmazonS3/latest/dev/NotificationHowTo.html#notification-how-to-event-types-and-destinations) for which to send notifications.
   152  * `filter_prefix` - (Optional) Specifies object key name prefix.
   153  * `filter_suffix` - (Optional) Specifies object key name suffix.
   154  
   155  The `queue` notification configuration supports the following:
   156  
   157  * `id` - (Optional) Specifies unique identifier for each of the notification configurations.
   158  * `queue_arn` - (Required) Specifies Amazon SQS queue ARN.
   159  * `events` - (Required) Specifies [event](http://docs.aws.amazon.com/AmazonS3/latest/dev/NotificationHowTo.html#notification-how-to-event-types-and-destinations) for which to send notifications.
   160  * `filter_prefix` - (Optional) Specifies object key name prefix.
   161  * `filter_suffix` - (Optional) Specifies object key name suffix.
   162  
   163  The `lambda_function` notification configuration supports the following:
   164  
   165  * `id` - (Optional) Specifies unique identifier for each of the notification configurations.
   166  * `lambda_function_arn` - (Required) Specifies Amazon Lambda function ARN.
   167  * `events` - (Required) Specifies [event](http://docs.aws.amazon.com/AmazonS3/latest/dev/NotificationHowTo.html#notification-how-to-event-types-and-destinations) for which to send notifications.
   168  * `filter_prefix` - (Optional) Specifies object key name prefix.
   169  * `filter_suffix` - (Optional) Specifies object key name suffix.
   170