mirror of
https://github.com/FoggedLens/deflock.git
synced 2026-02-12 15:02:45 +00:00
fix alpr_counts lambda which has been timing out
This commit is contained in:
@@ -23,11 +23,11 @@ def fetch_alpr_surveillance_nodes(usOnly=False):
|
||||
return {"error": f"Failed to fetch data from Overpass API. Status code: {response.status_code}"}
|
||||
|
||||
def lambda_handler(event, context):
|
||||
us_alprs = fetch_alpr_surveillance_nodes('(area["ISO3166-1"="US"])')
|
||||
# us_alprs = fetch_alpr_surveillance_nodes('(area["ISO3166-1"="US"])')
|
||||
worldwide_alprs = fetch_alpr_surveillance_nodes()
|
||||
|
||||
all_alprs = {
|
||||
'us': us_alprs,
|
||||
# 'us': us_alprs,
|
||||
'worldwide': worldwide_alprs
|
||||
}
|
||||
|
||||
|
||||
@@ -68,7 +68,7 @@ resource "aws_lambda_function" "overpass_lambda" {
|
||||
handler = "${var.module_name}.lambda_handler"
|
||||
runtime = "python3.9"
|
||||
source_code_hash = data.archive_file.python_lambda_package.output_base64sha256
|
||||
timeout = 30
|
||||
timeout = 60
|
||||
}
|
||||
|
||||
resource "aws_cloudwatch_event_rule" "lambda_rule" {
|
||||
@@ -90,3 +90,33 @@ resource "aws_lambda_permission" "allow_cloudwatch_to_call_lambda" {
|
||||
principal = "events.amazonaws.com"
|
||||
source_arn = aws_cloudwatch_event_rule.lambda_rule.arn
|
||||
}
|
||||
|
||||
resource "aws_cloudwatch_log_group" "lambda_log_group" {
|
||||
name = "/aws/lambda/${var.module_name}"
|
||||
retention_in_days = 14
|
||||
}
|
||||
|
||||
resource "aws_iam_policy" "lambda_cloudwatch_logs_policy" {
|
||||
name = "lambda_cloudwatch_logs_policy"
|
||||
description = "Policy for Lambda to write logs to CloudWatch"
|
||||
|
||||
policy = jsonencode({
|
||||
Version = "2012-10-17",
|
||||
Statement = [
|
||||
{
|
||||
Action = [
|
||||
"logs:CreateLogGroup",
|
||||
"logs:CreateLogStream",
|
||||
"logs:PutLogEvents"
|
||||
]
|
||||
Effect = "Allow"
|
||||
Resource = "arn:aws:logs:${var.aws_region}:${var.aws_account_id}:log-group:/aws/lambda/${var.module_name}:*"
|
||||
}
|
||||
]
|
||||
})
|
||||
}
|
||||
|
||||
resource "aws_iam_role_policy_attachment" "lambda_cloudwatch_logs_attachment" {
|
||||
role = aws_iam_role.lambda_role.name
|
||||
policy_arn = aws_iam_policy.lambda_cloudwatch_logs_policy.arn
|
||||
}
|
||||
|
||||
@@ -14,3 +14,15 @@ variable "deflock_stats_bucket" {
|
||||
variable "rate" {
|
||||
description = "Rate at which to run the Lambda function"
|
||||
}
|
||||
|
||||
variable "aws_region" {
|
||||
description = "The AWS region where resources will be created"
|
||||
type = string
|
||||
default = "us-east-1"
|
||||
}
|
||||
|
||||
variable "aws_account_id" {
|
||||
description = "The AWS account ID where resources will be created"
|
||||
type = string
|
||||
default = "912821578123"
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user