Skip to content

Commit d4e7065

Browse files
committed
VED-901: Update extended attribute file destination. (#1141)
* VED-901: Update extended attributes destination prefix. * VED-901: Update tests. * VED-901: Upload EA files directly to the S3 submission upload bucket. * VED-901: Lint tfvars files.
1 parent b519993 commit d4e7065

6 files changed

Lines changed: 27 additions & 29 deletions

File tree

infrastructure/instance/environments/prod/blue/variables.tfvars

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,4 +6,5 @@ pds_environment = "prod"
66
batch_error_notifications_enabled = true
77
create_mesh_processor = true
88
has_sub_environment_scope = false
9-
dspp_kms_key_alias = "nhsd-dspp-core-prod-extended-attributes-gdp-key"
9+
dspp_submission_s3_bucket_name = "nhsd-dspp-core-prod-s3-submission-upload"
10+
dspp_submission_kms_key_alias = "nhsd-dspp-core-prod-s3-submission-upload-key"

infrastructure/instance/environments/prod/green/variables.tfvars

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,4 +6,5 @@ pds_environment = "prod"
66
batch_error_notifications_enabled = true
77
create_mesh_processor = true
88
has_sub_environment_scope = false
9-
dspp_kms_key_alias = "nhsd-dspp-core-prod-extended-attributes-gdp-key"
9+
dspp_submission_s3_bucket_name = "nhsd-dspp-core-prod-s3-submission-upload"
10+
dspp_submission_kms_key_alias = "nhsd-dspp-core-prod-s3-submission-upload-key"

infrastructure/instance/file_name_processor.tf

Lines changed: 9 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -3,18 +3,8 @@ locals {
33
filename_lambda_dir = abspath("${path.root}/../../lambdas/filenameprocessor")
44
filename_lambda_files = fileset(local.filename_lambda_dir, "**")
55
filename_lambda_dir_sha = sha1(join("", [for f in local.filename_lambda_files : filesha1("${local.filename_lambda_dir}/${f}")]))
6-
dps_bucket_name_for_extended_attribute = (
7-
var.environment == "prod"
8-
? "nhsd-dspp-core-prod-extended-attributes-gdp"
9-
: "nhsd-dspp-core-ref-extended-attributes-gdp"
10-
)
11-
dps_bucket_arn_for_extended_attribute = [
12-
"arn:aws:s3:::${local.dps_bucket_name_for_extended_attribute}/*"
13-
]
146
}
157

16-
17-
188
resource "aws_ecr_repository" "file_name_processor_lambda_repository" {
199
image_scanning_configuration {
2010
scan_on_push = true
@@ -79,7 +69,7 @@ resource "aws_ecr_repository_policy" "filenameprocessor_lambda_ECRImageRetreival
7969
],
8070
"Condition" : {
8171
"StringLike" : {
82-
"aws:sourceArn" : "arn:aws:lambda:eu-west-2:${var.immunisation_account_id}:function:${local.short_prefix}-filenameproc_lambda"
72+
"aws:sourceArn" : "arn:aws:lambda:eu-west-2:${var.immunisation_account_id}:function:${local.short_prefix}-filenameproc-lambda"
8373
}
8474
}
8575
}
@@ -116,7 +106,7 @@ resource "aws_iam_policy" "filenameprocessor_lambda_exec_policy" {
116106
"logs:CreateLogStream",
117107
"logs:PutLogEvents"
118108
]
119-
Resource = "arn:aws:logs:${var.aws_region}:${var.immunisation_account_id}:log-group:/aws/lambda/${local.short_prefix}-filenameproc_lambda:*"
109+
Resource = "arn:aws:logs:${var.aws_region}:${var.immunisation_account_id}:log-group:/aws/lambda/${local.short_prefix}-filenameproc-lambda:*"
120110
},
121111
{
122112
Effect = "Allow"
@@ -178,7 +168,7 @@ resource "aws_iam_policy" "filenameprocessor_lambda_exec_policy" {
178168
"Action" : [
179169
"s3:PutObject"
180170
],
181-
"Resource" : local.dps_bucket_arn_for_extended_attribute
171+
"Resource" : ["arn:aws:s3:::${var.dspp_submission_s3_bucket_name}/*"]
182172
}
183173
]
184174
})
@@ -264,14 +254,14 @@ resource "aws_iam_policy" "filenameprocessor_dps_extended_attribute_kms_policy"
264254
{
265255
Effect = "Allow",
266256
Action = [
267-
"kms:Decrypt",
257+
"kms:Encrypt",
268258
"kms:GenerateDataKey",
269-
"kms:DescribeKey"
259+
"kms:DescribeKey",
270260
],
271261
Resource = "arn:aws:kms:eu-west-2:${var.dspp_core_account_id}:key/*",
272262
"Condition" = {
273263
"ForAnyValue:StringEquals" = {
274-
"kms:ResourceAliases" = "alias/${var.dspp_kms_key_alias}"
264+
"kms:ResourceAliases" = "alias/${var.dspp_submission_kms_key_alias}"
275265
}
276266
}
277267
}
@@ -311,7 +301,7 @@ resource "aws_iam_role_policy_attachment" "filenameprocessor_lambda_dynamo_acces
311301

312302
# Lambda Function with Security Group and VPC.
313303
resource "aws_lambda_function" "file_processor_lambda" {
314-
function_name = "${local.short_prefix}-filenameproc_lambda"
304+
function_name = "${local.short_prefix}-filenameproc-lambda"
315305
role = aws_iam_role.filenameprocessor_lambda_exec_role.arn
316306
package_type = "Image"
317307
image_uri = module.file_processor_docker_image.image_uri
@@ -329,7 +319,7 @@ resource "aws_lambda_function" "file_processor_lambda" {
329319
DPS_ACCOUNT_ID = var.dspp_core_account_id
330320
SOURCE_BUCKET_NAME = aws_s3_bucket.batch_data_source_bucket.bucket
331321
ACK_BUCKET_NAME = aws_s3_bucket.batch_data_destination_bucket.bucket
332-
DPS_BUCKET_NAME = local.dps_bucket_name_for_extended_attribute
322+
DPS_BUCKET_NAME = var.dspp_submission_s3_bucket_name
333323
QUEUE_URL = aws_sqs_queue.batch_file_created.url
334324
REDIS_HOST = data.aws_elasticache_cluster.existing_redis.cache_nodes[0].address
335325
REDIS_PORT = data.aws_elasticache_cluster.existing_redis.cache_nodes[0].port
@@ -371,7 +361,7 @@ resource "aws_s3_bucket_notification" "datasources_lambda_notification" {
371361
}
372362

373363
resource "aws_cloudwatch_log_group" "file_name_processor_log_group" {
374-
name = "/aws/lambda/${local.short_prefix}-filenameproc_lambda"
364+
name = "/aws/lambda/${local.short_prefix}-filenameproc-lambda"
375365
retention_in_days = 30
376366
}
377367

infrastructure/instance/variables.tf

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -27,10 +27,16 @@ variable "mns_account_id" {
2727
default = "631615744739"
2828
}
2929

30-
variable "dspp_kms_key_alias" {
31-
description = "Alias name of the DPS KMS key allowed for SSE-KMS encryption"
30+
variable "dspp_submission_s3_bucket_name" {
31+
description = "Name of the DSPP (DPS) S3 bucket where extended attributes files should be submitted"
3232
type = string
33-
default = "nhsd-dspp-core-ref-extended-attributes-gdp-key"
33+
default = "nhsd-dspp-core-ref-s3-submission-upload"
34+
}
35+
36+
variable "dspp_submission_kms_key_alias" {
37+
description = "Alias of the DSPP (DPS) KMS key required to encrypt extended attributes files"
38+
type = string
39+
default = "nhsd-dspp-core-ref-s3-submission-upload-key"
3440
}
3541

3642
variable "create_mesh_processor" {

lambdas/filenameprocessor/src/constants.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@
2727
# Currently only COVID extended attributes files are supported, might be extended in future for other vaccine types
2828
EXTENDED_ATTRIBUTES_VACC_TYPE = "COVID"
2929

30-
DPS_DESTINATION_PREFIX = "dps_destination"
30+
DPS_DESTINATION_PREFIX = "generic/EXTENDED_ATTRIBUTES_DAILY_1"
3131
EXTENDED_ATTRIBUTES_ARCHIVE_PREFIX = "extended-attributes-archive"
3232
VALID_EA_VERSIONS = ["V1_5"]
3333
ERROR_TYPE_TO_STATUS_CODE_MAP = {

lambdas/filenameprocessor/tests/test_lambda_handler.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -292,8 +292,8 @@ def test_lambda_handler_extended_attributes_success(self, mock_get_redis_client)
292292
archived_obj = s3_client.get_object(Bucket=BucketNames.SOURCE, Key=archived_key)
293293
self.assertIsNotNone(archived_obj)
294294

295-
# Also verify file copied to DPS destination bucket under dps_destination/<file_key>
296-
dps_key = f"dps_destination/{test_cases[0].file_key}"
295+
# Also verify file copied to DPS destination bucket under generic/EXTENDED_ATTRIBUTES_DAILY_1/<file_key>
296+
dps_key = f"generic/EXTENDED_ATTRIBUTES_DAILY_1/{test_cases[0].file_key}"
297297
copied_obj = s3_client.get_object(Bucket=BucketNames.DPS_DESTINATION, Key=dps_key)
298298
self.assertIsNotNone(copied_obj)
299299

@@ -467,7 +467,7 @@ def test_lambda_handler_extended_attributes_extension_checks(self, mock_get_redi
467467
# Ensure processed path hit by checking archive move in source bucket
468468
s3_client.get_object(Bucket=BucketNames.SOURCE, Key=f"extended-attributes-archive/{csv_key}")
469469
# And verify copy to DPS destination
470-
s3_client.get_object(Bucket=BucketNames.DPS_DESTINATION, Key=f"dps_destination/{csv_key}")
470+
s3_client.get_object(Bucket=BucketNames.DPS_DESTINATION, Key=f"generic/EXTENDED_ATTRIBUTES_DAILY_1/{csv_key}")
471471

472472
# .DAT accepted
473473
dat_key = MockFileDetails.extended_attributes_file.file_key[:-3] + "dat"
@@ -478,7 +478,7 @@ def test_lambda_handler_extended_attributes_extension_checks(self, mock_get_redi
478478
):
479479
lambda_handler(self.make_event([self.make_record(dat_key)]), None)
480480
s3_client.get_object(Bucket=BucketNames.SOURCE, Key=f"extended-attributes-archive/{dat_key}")
481-
s3_client.get_object(Bucket=BucketNames.DPS_DESTINATION, Key=f"dps_destination/{dat_key}")
481+
s3_client.get_object(Bucket=BucketNames.DPS_DESTINATION, Key=f"generic/EXTENDED_ATTRIBUTES_DAILY_1/{dat_key}")
482482

483483
# Invalid extension fails
484484
bad_ext_key = csv_key[:-3] + "txt"

0 commit comments

Comments
 (0)