Skip to content

Commit da2904e

Browse files
authored
feat: added filter criteria for event source mappings (#61)
1 parent 0181ecb commit da2904e

File tree

20 files changed

+572
-356
lines changed

20 files changed

+572
-356
lines changed

README.md

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -128,6 +128,13 @@ module "lambda" {
128128
batch_size = 50
129129
starting_position = "LATEST"
130130
131+
// Lambda event filtering, see https://docs.aws.amazon.com/lambda/latest/dg/invocation-eventfiltering.html
132+
filter_criteria = {
133+
pattern = jsonencode({
134+
eventName : ["MODIFY"]
135+
})
136+
}
137+
131138
// optionally configure a SNS or SQS destination for discarded batches, required IAM
132139
// permissions will be added automatically by this module,
133140
// see https://docs.aws.amazon.com/lambda/latest/dg/invocation-eventsourcemapping.html
@@ -201,9 +208,9 @@ see [example](examples/with-cloudwatch-logs-subscription) for details
201208
module "lambda" {
202209
// see above
203210
204-
// disable CloudWatch logs
205-
// cloudwatch_logs_enabled = false
206-
211+
// disable CloudWatch logs
212+
// cloudwatch_logs_enabled = false
213+
207214
cloudwatch_logs_retention_in_days = 14
208215
209216
cloudwatch_log_subscription_filters = {
@@ -239,8 +246,6 @@ module "lambda" {
239246
}
240247
```
241248

242-
243-
244249
For `image` deployment packages, the Lambda Insights extension needs to be added to the [container image](https://docs.aws.amazon.com/AmazonCloudWatch/latest/monitoring/Lambda-Insights-Getting-Started-docker.html):
245250

246251
```dockerfile
@@ -297,13 +302,13 @@ should migrate to this module as a drop-in replacement to benefit from new featu
297302
| Name | Version |
298303
|------|---------|
299304
| <a name="requirement_terraform"></a> [terraform](#requirement\_terraform) | >= 0.12.0 |
300-
| <a name="requirement_aws"></a> [aws](#requirement\_aws) | >= 3.61 |
305+
| <a name="requirement_aws"></a> [aws](#requirement\_aws) | >= 4.9 |
301306

302307
## Providers
303308

304309
| Name | Version |
305310
|------|---------|
306-
| <a name="provider_aws"></a> [aws](#provider\_aws) | 4.8.0 |
311+
| <a name="provider_aws"></a> [aws](#provider\_aws) | >= 4.9 |
307312

308313
## Modules
309314

docs/deployment/part2.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
| Name | Version |
44
|------|---------|
55
| <a name="requirement_terraform"></a> [terraform](#requirement\_terraform) | >= 0.12.0 |
6-
| <a name="requirement_aws"></a> [aws](#requirement\_aws) | >= 3.19 |
6+
| <a name="requirement_aws"></a> [aws](#requirement\_aws) | >= 4.9 |
77

88
## Providers
99

docs/part1.md

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -128,6 +128,13 @@ module "lambda" {
128128
batch_size = 50
129129
starting_position = "LATEST"
130130
131+
// Lambda event filtering, see https://docs.aws.amazon.com/lambda/latest/dg/invocation-eventfiltering.html
132+
filter_criteria = {
133+
pattern = jsonencode({
134+
eventName : ["MODIFY"]
135+
})
136+
}
137+
131138
// optionally configure a SNS or SQS destination for discarded batches, required IAM
132139
// permissions will be added automatically by this module,
133140
// see https://docs.aws.amazon.com/lambda/latest/dg/invocation-eventsourcemapping.html
@@ -201,9 +208,9 @@ see [example](examples/with-cloudwatch-logs-subscription) for details
201208
module "lambda" {
202209
// see above
203210
204-
// disable CloudWatch logs
205-
// cloudwatch_logs_enabled = false
206-
211+
// disable CloudWatch logs
212+
// cloudwatch_logs_enabled = false
213+
207214
cloudwatch_logs_retention_in_days = 14
208215
209216
cloudwatch_log_subscription_filters = {
@@ -239,8 +246,6 @@ module "lambda" {
239246
}
240247
```
241248

242-
243-
244249
For `image` deployment packages, the Lambda Insights extension needs to be added to the [container image](https://docs.aws.amazon.com/AmazonCloudWatch/latest/monitoring/Lambda-Insights-Getting-Started-docker.html):
245250

246251
```dockerfile

docs/part2.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,13 @@
33
| Name | Version |
44
|------|---------|
55
| <a name="requirement_terraform"></a> [terraform](#requirement\_terraform) | >= 0.12.0 |
6-
| <a name="requirement_aws"></a> [aws](#requirement\_aws) | >= 3.61 |
6+
| <a name="requirement_aws"></a> [aws](#requirement\_aws) | >= 4.9 |
77

88
## Providers
99

1010
| Name | Version |
1111
|------|---------|
12-
| <a name="provider_aws"></a> [aws](#provider\_aws) | 4.8.0 |
12+
| <a name="provider_aws"></a> [aws](#provider\_aws) | >= 4.9 |
1313

1414
## Modules
1515

event_source_mappings.tf

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,16 @@ resource "aws_lambda_event_source_mapping" "event_source" {
4848
}
4949
}
5050
}
51+
52+
dynamic "filter_criteria" {
53+
for_each = try(each.value["filter_criteria"], null) != null ? [true] : []
54+
55+
content {
56+
filter {
57+
pattern = try(each.value["filter_criteria"].pattern, null)
58+
}
59+
}
60+
}
5161
}
5262

5363
// type specific minimal permissions for supported event_sources,

examples/deployment/container-image/versions.tf

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,6 @@ terraform {
22
required_version = ">= 0.12"
33

44
required_providers {
5-
aws = ">= 3.61"
5+
aws = ">= 4.9"
66
}
77
}

examples/deployment/s3/versions.tf

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,6 @@ terraform {
22
required_version = ">= 0.12"
33

44
required_providers {
5-
aws = ">= 3.61"
5+
aws = ">= 4.9"
66
}
77
}

examples/simple/versions.tf

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,6 @@ terraform {
22
required_version = ">= 0.12"
33

44
required_providers {
5-
aws = ">= 3.61"
5+
aws = ">= 4.9"
66
}
77
}

examples/with-cloudwatch-event-rules/versions.tf

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,6 @@ terraform {
22
required_version = ">= 0.12"
33

44
required_providers {
5-
aws = ">= 3.61"
5+
aws = ">= 4.9"
66
}
77
}

examples/with-cloudwatch-logs-subscription/versions.tf

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,6 @@ terraform {
22
required_version = ">= 0.12"
33

44
required_providers {
5-
aws = ">= 3.19"
5+
aws = ">= 4.9"
66
}
77
}

0 commit comments

Comments
 (0)