File tree Expand file tree Collapse file tree 5 files changed +89
-26
lines changed
examples/with-event-source-mappings Expand file tree Collapse file tree 5 files changed +89
-26
lines changed Original file line number Diff line number Diff line change @@ -135,13 +135,6 @@ module "lambda" {
135135 batch_size = 50
136136 starting_position = "LATEST"
137137
138- // Lambda event filtering, see https://docs.aws.amazon.com/lambda/latest/dg/invocation-eventfiltering.html
139- filter_criteria = {
140- pattern = jsonencode({
141- eventName : ["MODIFY"]
142- })
143- }
144-
145138 // optionally configure a SNS or SQS destination for discarded batches, required IAM
146139 // permissions will be added automatically by this module,
147140 // see https://docs.aws.amazon.com/lambda/latest/dg/invocation-eventsourcemapping.html
@@ -150,6 +143,24 @@ module "lambda" {
150143 // optionally overwrite function_name in case an alias should be used in the
151144 // event source mapping, see https://docs.aws.amazon.com/lambda/latest/dg/configuration-aliases.html
152145 function_name = aws_lambda_alias.example.arn
146+
147+ // Lambda event filtering, see https://docs.aws.amazon.com/lambda/latest/dg/invocation-eventfiltering.html
148+ filter_criteria = [
149+ {
150+ pattern = jsonencode({
151+ data : {
152+ Key1 : ["Value1"]
153+ }
154+ })
155+ },
156+ {
157+ pattern = jsonencode({
158+ data : {
159+ Key2 : [{ "anything-but" : ["Value2"] }]
160+ }
161+ })
162+ }
163+ ]
153164 }
154165
155166 table_2 = {
Original file line number Diff line number Diff line change @@ -57,11 +57,15 @@ resource "aws_lambda_event_source_mapping" "event_source" {
5757 }
5858
5959 dynamic "filter_criteria" {
60- for_each = try (each. value [ " filter_criteria" ] , null ) != null ? [true ] : []
60+ for_each = try (each. value . filter_criteria , null ) != null ? [true ] : []
6161
6262 content {
63- filter {
64- pattern = try (each. value [" filter_criteria" ]. pattern , null )
63+ dynamic "filter" {
64+ for_each = try (flatten ([each . value . filter_criteria ]), [])
65+
66+ content {
67+ pattern = try (filter. value . pattern , null )
68+ }
6569 }
6670 }
6771 }
Original file line number Diff line number Diff line change @@ -64,25 +64,37 @@ module "lambda" {
6464 table_1 = {
6565 event_source_arn = aws_dynamodb_table.table_1.stream_arn
6666
67+ // optionally overwrite function_name in case an alias should be used in the
68+ // event source mapping, see https://docs.aws.amazon.com/lambda/latest/dg/configuration-aliases.html
69+ function_name = aws_lambda_alias.example.arn
70+
6771 // optionally overwrite arguments from https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/lambda_event_source_mapping
6872 batch_size = 50
6973 maximum_retry_attempts = 3
7074
71- // Lambda event filtering, see https://docs.aws.amazon.com/lambda/latest/dg/invocation-eventfiltering.html
72- filter_criteria = {
73- pattern = jsonencode ({
74- eventName : [" MODIFY" ]
75- })
76- }
77-
7875 // optionally configure a SNS or SQS destination for discarded batches, required IAM
7976 // permissions will be added automatically by this module,
8077 // see https://docs.aws.amazon.com/lambda/latest/dg/invocation-eventsourcemapping.html
8178 destination_arn_on_failure = aws_sqs_queue.errors.arn
8279
83- // optionally overwrite function_name in case an alias should be used in the
84- // event source mapping, see https://docs.aws.amazon.com/lambda/latest/dg/configuration-aliases.html
85- function_name = aws_lambda_alias.example.arn
80+
81+ // Lambda event filtering, see https://docs.aws.amazon.com/lambda/latest/dg/invocation-eventfiltering.html
82+ filter_criteria = [
83+ {
84+ pattern = jsonencode ({
85+ data : {
86+ Key1 : [" Value1" ]
87+ }
88+ })
89+ },
90+ {
91+ pattern = jsonencode ({
92+ data : {
93+ Key2 : [{ " anything-but" : [" Value2" ] }]
94+ }
95+ })
96+ }
97+ ]
8698 }
8799
88100 table_2 = {
Original file line number Diff line number Diff line change @@ -36,13 +36,31 @@ module "lambda" {
3636 stream_1 = {
3737 event_source_arn = aws_kinesis_stream.stream_1.arn
3838
39+ // optionally overwrite function_name in case an alias should be used in the
40+ // event source mapping, see https://docs.aws.amazon.com/lambda/latest/dg/configuration-aliases.html
41+ // function_name = aws_lambda_alias.example.arn
42+
3943 // optionally overwrite arguments from https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/lambda_event_source_mapping
4044 batch_size = 50
4145 starting_position = " LATEST" // optionally overwrite default 'starting_position'
4246
43- // optionally overwrite function_name in case an alias should be used in the
44- // event source mapping, see https://docs.aws.amazon.com/lambda/latest/dg/configuration-aliases.html
45- // function_name = aws_lambda_alias.example.arn
47+ // Lambda event filtering, see https://docs.aws.amazon.com/lambda/latest/dg/invocation-eventfiltering.html
48+ filter_criteria = [
49+ {
50+ pattern = jsonencode ({
51+ data : {
52+ Key1 : [" Value1" ]
53+ }
54+ })
55+ },
56+ {
57+ pattern = jsonencode ({
58+ data : {
59+ Key2 : [{ " anything-but" : [" Value2" ] }]
60+ }
61+ })
62+ }
63+ ]
4664 }
4765
4866 stream_2 = {
Original file line number Diff line number Diff line change @@ -32,16 +32,34 @@ module "lambda" {
3232 queue_1 = {
3333 event_source_arn = aws_sqs_queue.queue_1.arn
3434
35+ // optionally overwrite function_name in case an alias should be used in the
36+ // event source mapping, see https://docs.aws.amazon.com/lambda/latest/dg/configuration-aliases.html
37+ // function_name = aws_lambda_alias.example.arn
38+
3539 // optionally overwrite arguments from https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/lambda_event_source_mapping
3640 batch_size = 5
3741
3842 scaling_config = {
3943 maximum_concurrency = 2
4044 }
4145
42- // optionally overwrite function_name in case an alias should be used in the
43- // event source mapping, see https://docs.aws.amazon.com/lambda/latest/dg/configuration-aliases.html
44- // function_name = aws_lambda_alias.example.arn
46+ // Lambda event filtering, see https://docs.aws.amazon.com/lambda/latest/dg/invocation-eventfiltering.html
47+ filter_criteria = [
48+ {
49+ pattern = jsonencode ({
50+ body : {
51+ Key1 : [" Value1" ]
52+ }
53+ })
54+ },
55+ {
56+ pattern = jsonencode ({
57+ body : {
58+ Key2 : [{ " anything-but" : [" Value2" ] }]
59+ }
60+ })
61+ }
62+ ]
4563 }
4664
4765 queue_2 = {
You can’t perform that action at this time.
0 commit comments