|
@@ -1,5 +1,11 @@
|
|
|
+locals {
|
|
|
+ # By default, We allow lambda to run 5 seconds less than the visibility timeout, unless
|
|
|
+ # the visiblity timeout is > 300 (5 minutes)
|
|
|
+ lambda_timeout = (var.source_sqs.visibility_timeout_seconds > 300 ? 300 : (var.source_sqs.visibility_timeout_seconds - 5))
|
|
|
+}
|
|
|
+
|
|
|
resource "aws_lambda_event_source_mapping" "sqs_fair_queue" {
|
|
|
- event_source_arn = var.source_sqs_arn
|
|
|
+ event_source_arn = var.source_sqs.arn
|
|
|
function_name = aws_lambda_function.sqs_fair_queue.arn
|
|
|
batch_size = 100
|
|
|
maximum_batching_window_in_seconds = 30 # How long to wait to gather a batch, max: 300
|
|
@@ -19,7 +25,7 @@ resource "aws_lambda_function" "sqs_fair_queue" {
|
|
|
function_name = "sqs_fair_queue_${var.sqs_prefix}"
|
|
|
role = aws_iam_role.sqs_fair_queue.arn
|
|
|
handler = "sqs_fair_queue.lambda_handler"
|
|
|
- timeout = var.lambda_timeout
|
|
|
+ timeout = local.lambda_timeout
|
|
|
# NOTE: If it can't handle the batch in the time alloted, there is a chance for duplicates.
|
|
|
|
|
|
source_code_hash = data.archive_file.sqs_fair_queue.output_base64sha256
|
|
@@ -28,8 +34,8 @@ resource "aws_lambda_function" "sqs_fair_queue" {
|
|
|
|
|
|
environment {
|
|
|
variables = {
|
|
|
- #"SOURCE_SQS_ARN" = var.source_sqs_arn Not needed?
|
|
|
- "SOURCE_SQS_URL" = var.source_sqs_url
|
|
|
+ #"SOURCE_SQS_ARN" = var.source_sqs.arn # Not needed?
|
|
|
+ "SOURCE_SQS_URL" = var.source_sqs.url
|
|
|
"SQS_PREFIX" = var.sqs_prefix
|
|
|
"NUM_QUEUES" = var.num_queues
|
|
|
"HASH_JSONPATH" = var.hash_jsonpath
|
|
@@ -49,14 +55,14 @@ resource "aws_lambda_permission" "sqs_fair_queue" {
|
|
|
action = "lambda:InvokeFunction"
|
|
|
function_name = aws_lambda_function.sqs_fair_queue.function_name
|
|
|
principal = "sqs.amazonaws.com"
|
|
|
- source_arn = var.source_sqs_arn
|
|
|
+ source_arn = var.source_sqs.arn
|
|
|
}
|
|
|
|
|
|
data "aws_iam_policy_document" "sqs_fair_queue" {
|
|
|
statement {
|
|
|
sid = "SQSIngest"
|
|
|
effect = "Allow"
|
|
|
- resources = [var.source_sqs_arn]
|
|
|
+ resources = [var.source_sqs.arn]
|
|
|
# tfsec:ignore:aws-iam-no-policy-wildcards Wildcards are fine and useful
|
|
|
actions = ["sqs:*"] # TODO: Nail down
|
|
|
# Probably:
|