update clustering code to segment regions, still cluster until next release for backward compat

This commit is contained in:
Will Freeman
2024-12-23 19:30:14 -08:00
parent 6f50bd32b7
commit be88a7950c
7 changed files with 116 additions and 20 deletions

View File

@@ -13,5 +13,6 @@ module "alpr_clusters" {
module_name = "alpr_clusters"
source = "./modules/alpr_clusters"
deflock_stats_bucket = var.deflock_stats_bucket
deflock_cdn_bucket = var.deflock_cdn_bucket
rate = "rate(1 day)"
}

View File

@@ -15,6 +15,11 @@ resource "aws_iam_role" "lambda_role" {
})
}
resource "aws_iam_role_policy_attachment" "lambda_basic_execution" {
role = aws_iam_role.lambda_role.name
policy_arn = "arn:aws:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole"
}
resource "aws_iam_policy" "lambda_s3_write_policy" {
name = "${var.module_name}_lambda_s3_write_policy"
description = "Policy for Lambda to write to S3 bucket ${var.deflock_stats_bucket}"
@@ -28,7 +33,10 @@ resource "aws_iam_policy" "lambda_s3_write_policy" {
"s3:PutObjectAcl"
]
Effect = "Allow"
Resource = "arn:aws:s3:::${var.deflock_stats_bucket}/${var.output_filename}"
Resource = [
"arn:aws:s3:::${var.deflock_cdn_bucket}/*",
"arn:aws:s3:::${var.deflock_stats_bucket}/*"
]
}
]
})
@@ -44,7 +52,13 @@ resource "aws_lambda_function" "overpass_lambda" {
role = aws_iam_role.lambda_role.arn
package_type = "Image"
image_uri = "${aws_ecr_repository.lambda_repository.repository_url}:latest"
timeout = 90
timeout = 180
memory_size = 1024
environment {
variables = {
UPDATE_RATE_MINS = var.rate
}
}
}
resource "aws_cloudwatch_event_rule" "lambda_rule" {
@@ -70,3 +84,8 @@ resource "aws_lambda_permission" "allow_cloudwatch_to_call_lambda" {
resource "aws_ecr_repository" "lambda_repository" {
name = "${var.module_name}-lambda"
}
resource "aws_cloudwatch_log_group" "lambda_log_group" {
name = "/aws/lambda/${aws_lambda_function.overpass_lambda.function_name}"
retention_in_days = 14
}

View File

@@ -11,6 +11,10 @@ variable "deflock_stats_bucket" {
description = "S3 bucket for the ALPR clusters JSON file"
}
variable "deflock_cdn_bucket" {
description = "S3 bucket for the CDN"
}
variable "rate" {
description = "Rate at which to run the Lambda function"
}

View File

@@ -2,3 +2,8 @@ variable "deflock_stats_bucket" {
description = "S3 bucket for the ALPR counts JSON file"
default = "deflock-clusters"
}
variable "deflock_cdn_bucket" {
description = "S3 bucket for the CDN"
default = "cdn.deflock.me"
}