Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 18 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -135,13 +135,6 @@ module "lambda" {
batch_size = 50
starting_position = "LATEST"

// Lambda event filtering, see https://docs.aws.amazon.com/lambda/latest/dg/invocation-eventfiltering.html
filter_criteria = {
pattern = jsonencode({
eventName : ["MODIFY"]
})
}

// optionally configure a SNS or SQS destination for discarded batches, required IAM
// permissions will be added automatically by this module,
// see https://docs.aws.amazon.com/lambda/latest/dg/invocation-eventsourcemapping.html
Expand All @@ -150,6 +143,24 @@ module "lambda" {
// optionally overwrite function_name in case an alias should be used in the
// event source mapping, see https://docs.aws.amazon.com/lambda/latest/dg/configuration-aliases.html
function_name = aws_lambda_alias.example.arn

// Lambda event filtering, see https://docs.aws.amazon.com/lambda/latest/dg/invocation-eventfiltering.html
filter_criteria = [
{
pattern = jsonencode({
data : {
Key1 : ["Value1"]
}
})
},
{
pattern = jsonencode({
data : {
Key2 : [{ "anything-but" : ["Value2"] }]
}
})
}
]
}

table_2 = {
Expand Down
10 changes: 7 additions & 3 deletions event_source_mappings.tf
Original file line number Diff line number Diff line change
Expand Up @@ -57,11 +57,15 @@ resource "aws_lambda_event_source_mapping" "event_source" {
}

dynamic "filter_criteria" {
for_each = try(each.value["filter_criteria"], null) != null ? [true] : []
for_each = try(each.value.filter_criteria, null) != null ? [true] : []

content {
filter {
pattern = try(each.value["filter_criteria"].pattern, null)
dynamic "filter" {
for_each = try(flatten([each.value.filter_criteria]), [])

content {
pattern = try(filter.value.pattern, null)
}
}
}
}
Expand Down
32 changes: 22 additions & 10 deletions examples/with-event-source-mappings/dynamodb-with-alias/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -64,25 +64,37 @@ module "lambda" {
table_1 = {
event_source_arn = aws_dynamodb_table.table_1.stream_arn

// optionally overwrite function_name in case an alias should be used in the
// event source mapping, see https://docs.aws.amazon.com/lambda/latest/dg/configuration-aliases.html
function_name = aws_lambda_alias.example.arn

// optionally overwrite arguments from https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/lambda_event_source_mapping
batch_size = 50
maximum_retry_attempts = 3

// Lambda event filtering, see https://docs.aws.amazon.com/lambda/latest/dg/invocation-eventfiltering.html
filter_criteria = {
pattern = jsonencode({
eventName : ["MODIFY"]
})
}

// optionally configure a SNS or SQS destination for discarded batches, required IAM
// permissions will be added automatically by this module,
// see https://docs.aws.amazon.com/lambda/latest/dg/invocation-eventsourcemapping.html
destination_arn_on_failure = aws_sqs_queue.errors.arn

// optionally overwrite function_name in case an alias should be used in the
// event source mapping, see https://docs.aws.amazon.com/lambda/latest/dg/configuration-aliases.html
function_name = aws_lambda_alias.example.arn

// Lambda event filtering, see https://docs.aws.amazon.com/lambda/latest/dg/invocation-eventfiltering.html
filter_criteria = [
{
pattern = jsonencode({
data : {
Key1 : ["Value1"]
}
})
},
{
pattern = jsonencode({
data : {
Key2 : [{ "anything-but" : ["Value2"] }]
}
})
}
]
}

table_2 = {
Expand Down
24 changes: 21 additions & 3 deletions examples/with-event-source-mappings/kinesis/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -36,13 +36,31 @@ module "lambda" {
stream_1 = {
event_source_arn = aws_kinesis_stream.stream_1.arn

// optionally overwrite function_name in case an alias should be used in the
// event source mapping, see https://docs.aws.amazon.com/lambda/latest/dg/configuration-aliases.html
// function_name = aws_lambda_alias.example.arn

// optionally overwrite arguments from https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/lambda_event_source_mapping
batch_size = 50
starting_position = "LATEST" // optionally overwrite default 'starting_position'

// optionally overwrite function_name in case an alias should be used in the
// event source mapping, see https://docs.aws.amazon.com/lambda/latest/dg/configuration-aliases.html
// function_name = aws_lambda_alias.example.arn
// Lambda event filtering, see https://docs.aws.amazon.com/lambda/latest/dg/invocation-eventfiltering.html
filter_criteria = [
{
pattern = jsonencode({
data : {
Key1 : ["Value1"]
}
})
},
{
pattern = jsonencode({
data : {
Key2 : [{ "anything-but" : ["Value2"] }]
}
})
}
]
}

stream_2 = {
Expand Down
24 changes: 21 additions & 3 deletions examples/with-event-source-mappings/sqs/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -32,16 +32,34 @@ module "lambda" {
queue_1 = {
event_source_arn = aws_sqs_queue.queue_1.arn

// optionally overwrite function_name in case an alias should be used in the
// event source mapping, see https://docs.aws.amazon.com/lambda/latest/dg/configuration-aliases.html
// function_name = aws_lambda_alias.example.arn

// optionally overwrite arguments from https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/lambda_event_source_mapping
batch_size = 5

scaling_config = {
maximum_concurrency = 2
}

// optionally overwrite function_name in case an alias should be used in the
// event source mapping, see https://docs.aws.amazon.com/lambda/latest/dg/configuration-aliases.html
// function_name = aws_lambda_alias.example.arn
// Lambda event filtering, see https://docs.aws.amazon.com/lambda/latest/dg/invocation-eventfiltering.html
filter_criteria = [
{
pattern = jsonencode({
body : {
Key1 : ["Value1"]
}
})
},
{
pattern = jsonencode({
body : {
Key2 : [{ "anything-but" : ["Value2"] }]
}
})
}
]
}

queue_2 = {
Expand Down