|
1 | 1 | # Lambda function to automatically create/delete Glue Catalog tables |
2 | 2 | # Workflow: S3 CSV upload/delete → SQS → Lambda → Glue Catalog table create/delete (retry once on failure → DLQ) |
3 | 3 |
|
| 4 | +locals { |
| 5 | + department_user_uploads_prefixes = { |
| 6 | + parking = "parking/" |
| 7 | + housing = "housing/" |
| 8 | + data_and_insight = "data-and-insight/" |
| 9 | + child_fam_services = "child-fam-services/" |
| 10 | + unrestricted = "unrestricted/" |
| 11 | + env_services = "env-services/" |
| 12 | + } |
| 13 | +} |
| 14 | + |
4 | 15 | data "aws_iam_policy_document" "csv_to_glue_catalog_lambda_assume_role" { |
5 | 16 | statement { |
6 | 17 | actions = ["sts:AssumeRole"] |
@@ -34,12 +45,11 @@ data "aws_iam_policy_document" "csv_to_glue_catalog_lambda_execution" { |
34 | 45 | "glue:GetPartitions", |
35 | 46 | "glue:DeletePartition", |
36 | 47 | ] |
37 | | - # Currently only scoped to parking |
38 | | - resources = [ |
39 | | - "arn:aws:glue:${data.aws_region.current.name}:${data.aws_caller_identity.data_platform.account_id}:catalog", |
40 | | - "arn:aws:glue:${data.aws_region.current.name}:${data.aws_caller_identity.data_platform.account_id}:database/parking_user_uploads_db", |
41 | | - "arn:aws:glue:${data.aws_region.current.name}:${data.aws_caller_identity.data_platform.account_id}:table/parking_user_uploads_db/*", |
42 | | - ] |
| 48 | + resources = concat( |
| 49 | + ["arn:aws:glue:${data.aws_region.current.name}:${data.aws_caller_identity.data_platform.account_id}:catalog"], |
| 50 | + [for db_name in values(local.department_user_uploads_databases) : "arn:aws:glue:${data.aws_region.current.name}:${data.aws_caller_identity.data_platform.account_id}:database/${db_name}"], |
| 51 | + [for db_name in values(local.department_user_uploads_databases) : "arn:aws:glue:${data.aws_region.current.name}:${data.aws_caller_identity.data_platform.account_id}:table/${db_name}/*"] |
| 52 | + ) |
43 | 53 | } |
44 | 54 |
|
45 | 55 | statement { |
@@ -177,11 +187,14 @@ resource "aws_sqs_queue_policy" "csv_to_glue_catalog_events" { |
177 | 187 | resource "aws_s3_bucket_notification" "user_uploads_csv_notification" { |
178 | 188 | bucket = module.user_uploads_data_source.bucket_id |
179 | 189 |
|
180 | | - queue { |
181 | | - queue_arn = aws_sqs_queue.csv_to_glue_catalog_events.arn |
182 | | - events = ["s3:ObjectCreated:*", "s3:ObjectRemoved:*"] |
183 | | - filter_prefix = "parking/" # Currently only scoped to parking |
184 | | - filter_suffix = ".csv" |
| 190 | + dynamic "queue" { |
| 191 | + for_each = local.department_user_uploads_prefixes |
| 192 | + content { |
| 193 | + queue_arn = aws_sqs_queue.csv_to_glue_catalog_events.arn |
| 194 | + events = ["s3:ObjectCreated:*", "s3:ObjectRemoved:*"] |
| 195 | + filter_prefix = queue.value |
| 196 | + filter_suffix = ".csv" |
| 197 | + } |
185 | 198 | } |
186 | 199 |
|
187 | 200 | depends_on = [aws_sqs_queue_policy.csv_to_glue_catalog_events] |
|
0 commit comments