Skip to content

Commit 94a0862

Browse files
authored
[PRMP-840] Add POST method and IAM roles for document review (#517)
Signed-off-by: NogaNHS <[email protected]>
1 parent e7dad78 commit 94a0862

File tree

4 files changed

+116
-1
lines changed

4 files changed

+116
-1
lines changed

infrastructure/api.tf

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,7 @@ resource "aws_api_gateway_deployment" "ndr_api_deploy" {
8484
module.document-status-check-gateway,
8585
module.document-status-check-lambda,
8686
module.post-document-references-fhir-lambda,
87+
module.post_document_review_lambda,
8788
module.patch_document_review_lambda,
8889
module.virus_scan_result_gateway,
8990
module.virus_scan_result_lambda

infrastructure/gateway-review-document.tf

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ module "review_document_gateway" {
22
source = "./modules/gateway"
33
api_gateway_id = aws_api_gateway_rest_api.ndr_doc_store_api.id
44
parent_id = aws_api_gateway_rest_api.ndr_doc_store_api.root_resource_id
5-
http_methods = ["GET"]
5+
http_methods = ["GET", "POST"]
66
authorization = "CUSTOM"
77
gateway_path = "DocumentReview"
88
authorizer_id = aws_api_gateway_authorizer.repo_authoriser.id

infrastructure/iam.tf

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -317,3 +317,41 @@ resource "aws_iam_role_policy_attachment" "get_doc_ref_presign_url" {
317317
role = aws_iam_role.get_doc_ref_presign_url_role.name
318318
policy_arn = aws_iam_policy.s3_document_data_policy_for_get_doc_ref_lambda.arn
319319
}
320+
321+
data "aws_iam_policy_document" "assume_role_policy_post_document_review_lambda" {
322+
statement {
323+
actions = ["sts:AssumeRole"]
324+
325+
principals {
326+
type = "AWS"
327+
identifiers = [module.post_document_review_lambda.lambda_execution_role_arn]
328+
}
329+
}
330+
}
331+
332+
resource "aws_iam_role" "post_document_review_presign" {
333+
name = "${terraform.workspace}_post_review_presign_url_role"
334+
assume_role_policy = data.aws_iam_policy_document.assume_role_policy_post_document_review_lambda.json
335+
}
336+
337+
resource "aws_iam_role_policy_attachment" "post_document_review" {
338+
role = aws_iam_role.post_document_review_presign.name
339+
policy_arn = aws_iam_policy.s3_document_data_policy_post_document_review_lambda.arn
340+
}
341+
342+
resource "aws_iam_policy" "s3_document_data_policy_post_document_review_lambda" {
343+
name = "${terraform.workspace}_put_document_only_policy_for_post_document_review_lambda"
344+
345+
policy = jsonencode({
346+
"Version" : "2012-10-17",
347+
"Statement" : [
348+
{
349+
"Effect" : "Allow",
350+
"Action" : [
351+
"s3:PutObject",
352+
],
353+
"Resource" : ["${module.ndr-bulk-staging-store.bucket_arn}/review/*"]
354+
}
355+
]
356+
})
357+
}
Lines changed: 76 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,76 @@
1+
module "post_document_review_lambda" {
2+
source = "./modules/lambda"
3+
name = "PostDocumentReview"
4+
handler = "handlers.post_document_review_handler.lambda_handler"
5+
iam_role_policy_documents = [
6+
module.ndr-app-config.app_config_policy,
7+
local.is_production ? "" : module.document_review_dynamodb_table[0].dynamodb_write_policy_document,
8+
local.is_production ? "" : module.document_review_dynamodb_table[0].dynamodb_read_policy_document,
9+
aws_iam_policy.ssm_access_policy.policy,
10+
module.ndr-bulk-staging-store.s3_write_policy_document,
11+
module.cloudfront_edge_dynamodb_table.dynamodb_write_policy_document,
12+
]
13+
14+
rest_api_id = aws_api_gateway_rest_api.ndr_doc_store_api.id
15+
api_execution_arn = aws_api_gateway_rest_api.ndr_doc_store_api.execution_arn
16+
http_methods = ["POST"]
17+
resource_id = module.review_document_gateway.gateway_resource_id
18+
kms_deletion_window = var.kms_deletion_window
19+
is_gateway_integration_needed = true
20+
is_invoked_from_gateway = true
21+
lambda_environment_variables = {
22+
APPCONFIG_APPLICATION = module.ndr-app-config.app_config_application_id
23+
APPCONFIG_ENVIRONMENT = module.ndr-app-config.app_config_environment_id
24+
APPCONFIG_CONFIGURATION = module.ndr-app-config.app_config_configuration_profile_id
25+
DOCUMENT_REVIEW_DYNAMODB_NAME = local.is_production ? "" : module.document_review_dynamodb_table[0].table_name
26+
PRESIGNED_ASSUME_ROLE = aws_iam_role.post_document_review_presign.arn
27+
WORKSPACE = terraform.workspace
28+
STAGING_STORE_BUCKET_NAME = module.ndr-bulk-staging-store.bucket_id
29+
EDGE_REFERENCE_TABLE = module.cloudfront_edge_dynamodb_table.table_name
30+
}
31+
depends_on = [
32+
aws_api_gateway_rest_api.ndr_doc_store_api,
33+
module.review_document_gateway
34+
]
35+
}
36+
37+
38+
module "post_document_review_lambda_alarm" {
39+
source = "./modules/lambda_alarms"
40+
lambda_function_name = module.post_document_review_lambda.function_name
41+
lambda_timeout = module.post_document_review_lambda.timeout
42+
lambda_name = "post_document_review_handler"
43+
namespace = "AWS/Lambda"
44+
alarm_actions = [module.post_document_review_lambda_alarm_topic.arn]
45+
ok_actions = [module.post_document_review_lambda_alarm_topic.arn]
46+
}
47+
48+
49+
module "post_document_review_lambda_alarm_topic" {
50+
source = "./modules/sns"
51+
sns_encryption_key_id = module.sns_encryption_key.id
52+
topic_name = "post-document-review-lambda-alarm-topic"
53+
topic_protocol = "lambda"
54+
topic_endpoint = module.post_document_review_lambda.lambda_arn
55+
delivery_policy = jsonencode({
56+
"Version" : "2012-10-17",
57+
"Statement" : [
58+
{
59+
"Effect" : "Allow",
60+
"Principal" : {
61+
"Service" : "cloudwatch.amazonaws.com"
62+
},
63+
"Action" : [
64+
"SNS:Publish",
65+
],
66+
"Condition" : {
67+
"ArnLike" : {
68+
"aws:SourceArn" : "arn:aws:cloudwatch:eu-west-2:${data.aws_caller_identity.current.account_id}:alarm:*"
69+
}
70+
}
71+
"Resource" : "*"
72+
}
73+
]
74+
})
75+
}
76+

0 commit comments

Comments
 (0)