From 5638c989fe1a5db7ae0310f4cc64d7a31cd2197a Mon Sep 17 00:00:00 2001
From: Rio Knightley <128376976+RioKnightleyNHS@users.noreply.github.com>
Date: Mon, 23 Oct 2023 14:43:20 +0100
Subject: [PATCH] Add bulk upload report lambda infrastructure
---
infrastructure/README.md | 4 ++-
infrastructure/lambda-bulk-upload-metadata.tf | 1 +
infrastructure/lambda-bulk-upload-report.tf | 26 +++++++++++++++++++
infrastructure/modules/dynamo_db/main.tf | 1 +
4 files changed, 31 insertions(+), 1 deletion(-)
create mode 100644 infrastructure/lambda-bulk-upload-report.tf
diff --git a/infrastructure/README.md b/infrastructure/README.md
index 3e0964f3..99200833 100644
--- a/infrastructure/README.md
+++ b/infrastructure/README.md
@@ -26,6 +26,7 @@
| [back\_channel\_logout\_lambda](#module\_back\_channel\_logout\_lambda) | ./modules/lambda | n/a |
| [bulk-upload-lambda](#module\_bulk-upload-lambda) | ./modules/lambda | n/a |
| [bulk-upload-metadata-lambda](#module\_bulk-upload-metadata-lambda) | ./modules/lambda | n/a |
+| [bulk-upload-report-lambda](#module\_bulk-upload-report-lambda) | ./modules/lambda | n/a |
| [bulk\_upload\_dynamodb\_table](#module\_bulk\_upload\_dynamodb\_table) | ./modules/dynamo_db | n/a |
| [create-doc-ref-gateway](#module\_create-doc-ref-gateway) | ./modules/gateway | n/a |
| [create-doc-ref-lambda](#module\_create-doc-ref-lambda) | ./modules/lambda | n/a |
@@ -97,7 +98,8 @@
| [aws_iam_policy.ssm_policy_pds](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/iam_policy) | resource |
| [aws_iam_policy.ssm_policy_token](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/iam_policy) | resource |
| [aws_lambda_event_source_mapping.bulk_upload_lambda](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/lambda_event_source_mapping) | resource |
-| [aws_s3_bucket_lifecycle_configuration.ndr-lifecycle-rules](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/s3_bucket_lifecycle_configuration) | resource |
+| [aws_s3_bucket_lifecycle_configuration.doc-store-lifecycle-rules](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/s3_bucket_lifecycle_configuration) | resource |
+| [aws_s3_bucket_lifecycle_configuration.lg-lifecycle-rules](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/s3_bucket_lifecycle_configuration) | resource |
| [aws_caller_identity.current](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/data-sources/caller_identity) | data source |
| [aws_iam_policy_document.alarm_notification_kms_key_policy_doc](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/data-sources/iam_policy_document) | data source |
diff --git a/infrastructure/lambda-bulk-upload-metadata.tf b/infrastructure/lambda-bulk-upload-metadata.tf
index bc5a8891..5ccd1511 100644
--- a/infrastructure/lambda-bulk-upload-metadata.tf
+++ b/infrastructure/lambda-bulk-upload-metadata.tf
@@ -19,6 +19,7 @@ module "bulk-upload-metadata-lambda" {
is_invoked_from_gateway = false
depends_on = [
+ aws_api_gateway_rest_api.ndr_doc_store_api,
module.ndr-bulk-staging-store,
module.sqs-lg-bulk-upload-metadata-queue,
]
diff --git a/infrastructure/lambda-bulk-upload-report.tf b/infrastructure/lambda-bulk-upload-report.tf
new file mode 100644
index 00000000..d4ac2be6
--- /dev/null
+++ b/infrastructure/lambda-bulk-upload-report.tf
@@ -0,0 +1,26 @@
+module "bulk-upload-report-lambda" {
+ source = "./modules/lambda"
+ name = "BulkUploadReportLambda"
+ handler = "handlers.bulk_upload_report_handler.lambda_handler"
+ iam_role_policies = [
+ "arn:aws:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole",
+ "arn:aws:iam::aws:policy/CloudWatchLambdaInsightsExecutionRolePolicy",
+ module.ndr-bulk-staging-store.s3_object_access_policy,
+ module.bulk_upload_dynamodb_table.dynamodb_policy
+ ]
+ rest_api_id = aws_api_gateway_rest_api.ndr_doc_store_api.id
+ api_execution_arn = aws_api_gateway_rest_api.ndr_doc_store_api.execution_arn
+ lambda_environment_variables = {
+ WORKSPACE = terraform.workspace
+ STAGING_STORE_BUCKET_NAME = "${terraform.workspace}-${var.staging_store_bucket_name}"
+ BULK_UPLOAD_DYNAMODB = "${terraform.workspace}_${var.bulk_upload_dynamodb_table_name}"
+ }
+ is_gateway_integration_needed = false
+ is_invoked_from_gateway = false
+
+ depends_on = [
+ aws_api_gateway_rest_api.ndr_doc_store_api,
+ module.ndr-bulk-staging-store,
+ module.bulk_upload_dynamodb_table
+ ]
+}
\ No newline at end of file
diff --git a/infrastructure/modules/dynamo_db/main.tf b/infrastructure/modules/dynamo_db/main.tf
index d4090d38..208675ac 100644
--- a/infrastructure/modules/dynamo_db/main.tf
+++ b/infrastructure/modules/dynamo_db/main.tf
@@ -36,6 +36,7 @@ resource "aws_dynamodb_table" "ndr_dynamodb_table" {
Workspace = terraform.workspace
}
}
+
resource "aws_iam_policy" "dynamodb_policy" {
name = "${terraform.workspace}_${var.table_name}_policy"
path = "/"