-
Notifications
You must be signed in to change notification settings - Fork 3
CCM-12614: Add PDM Poller component #147
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from 34 commits
Commits
Show all changes
42 commits
Select commit
Hold shift + click to select a range
aac68f4
CCM-12614: add basic lambda function
Ian-Hodges e56bd73
CCM-12614: add sqs queue and rule
Ian-Hodges 27f344f
CCM-12614: rename poll-pdm to pdm-poll
Ian-Hodges 7f417cf
Merge branch 'main' into feature/CCM-12614_pdm-poller
Ian-Hodges bf0685a
CCM-12614: add some basic event handling
Ian-Hodges 812b27b
CCM-12614: add call to pdm and various other bits
Ian-Hodges 9cb6fc1
Merge branch main into feature/CCM-12614_pdm-poller
Ian-Hodges 55410d9
CCM-12614: tidy up after merging in main
Ian-Hodges 44ee10c
CCM-12614: add component test and some clean up
Ian-Hodges 432c93c
CCM-12614: allow retryCount to be 0
Ian-Hodges a795299
CCM-12614: fix typo in schema definition
Ian-Hodges e67950f
CCM-12614: add some of the missing logic
Ian-Hodges d9c34c5
CCM-12614: add extra component tests
Ian-Hodges bfb5367
CCM-12614: add poll dlq component test
Ian-Hodges 6143fce
CCM-12614: fix for flaky build docs test
Ian-Hodges 3ee927d
CCM-12614: get nhs number and ods code from pdm response
Ian-Hodges 7d76c2a
CCM-12614: get nhs number and ods code from pdm response
Ian-Hodges c934f1f
CCM-12614: update pdm mock with an unavailable resource response
Ian-Hodges c02e087
CCM-12614: update pdm mock so it does not use iam_auth
Ian-Hodges 6a1a08f
CCM-12614: update pdm poll to use pdm mock when deployed
Ian-Hodges 8b5e2c1
CCM-12614: simplify the pdm mock authentication
Ian-Hodges 721d8bb
CCM-12614: update component test to use mock resource id
Ian-Hodges 4084304
CCM-12614: update to use local.csi
Ian-Hodges 0dc5ad3
CCM-12614: linting
Ian-Hodges 23b5a11
CCM-12614: linting
Ian-Hodges 3d0c413
CCM-12614: remove logging of sensitive data
Ian-Hodges c8c7f09
CCM-12614: remove unused npm packages
Ian-Hodges ed5ba2d
CCM-12614: update to retryCount description
Ian-Hodges 67125a3
CCM-12614: update and addition to component tests
Ian-Hodges deac2d4
CCM-12614: update event target resource names
Ian-Hodges 45696fa
CCM-12614: update event target resource names
Ian-Hodges c3682c1
CCM-12614: update all axios to latest version
Ian-Hodges 57c18fb
Merge branch 'main' into feature/CCM-12614_pdm-poller
Ian-Hodges f516918
CCM-12614: linting
Ian-Hodges 4bf5f07
CCM-12614: remove send_to_firehose
Ian-Hodges f9e9c26
CCM-12614: remove invalid fields
Ian-Hodges 1f386fc
CCM-12614: remove axios dependency
Ian-Hodges cd5fb9b
CCM-12614: update .gitleaksignore with a new ignore
Ian-Hodges bbffe19
CCM-12614: fix unavailable to available bug
Ian-Hodges 5d00f87
CCM-12614: fix unavailable to available bug
Ian-Hodges 9ae7309
Merge branch 'main' into feature/CCM-12614_pdm-poller
Ian-Hodges db26feb
CCM-12614: update lambda terraform to v2.0.29
Ian-Hodges File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
19 changes: 19 additions & 0 deletions
19
infrastructure/terraform/components/dl/cloudwatch_event_rule_pdm_resource_submitted.tf
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,19 @@ | ||
| resource "aws_cloudwatch_event_rule" "pdm_resource_submitted" { | ||
| name = "${local.csi}-pdm-resource-submitted" | ||
| description = "PDM resource submitted event rule" | ||
| event_bus_name = aws_cloudwatch_event_bus.main.name | ||
|
|
||
| event_pattern = jsonencode({ | ||
| "detail" : { | ||
| "type" : [ | ||
| "uk.nhs.notify.digital.letters.pdm.resource.submitted.v1" | ||
| ] | ||
| } | ||
| }) | ||
| } | ||
|
|
||
| resource "aws_cloudwatch_event_target" "pdm_resource_submitted_pdm_poll" { | ||
| rule = aws_cloudwatch_event_rule.pdm_resource_submitted.name | ||
| arn = module.sqs_pdm_poll.sqs_queue_arn | ||
| event_bus_name = aws_cloudwatch_event_bus.main.name | ||
| } |
19 changes: 19 additions & 0 deletions
19
infrastructure/terraform/components/dl/cloudwatch_event_rule_pdm_resource_unavailable.tf
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,19 @@ | ||
| resource "aws_cloudwatch_event_rule" "pdm_resource_unavailable" { | ||
| name = "${local.csi}-pdm-resource-unavailable" | ||
| description = "PDM resource unavailable event rule" | ||
| event_bus_name = aws_cloudwatch_event_bus.main.name | ||
|
|
||
| event_pattern = jsonencode({ | ||
| "detail" : { | ||
| "type" : [ | ||
| "uk.nhs.notify.digital.letters.pdm.resource.unavailable.v1" | ||
| ] | ||
| } | ||
| }) | ||
| } | ||
|
|
||
| resource "aws_cloudwatch_event_target" "pdm_resource_unavailable_pdm_poll" { | ||
| rule = aws_cloudwatch_event_rule.pdm_resource_unavailable.name | ||
| arn = module.sqs_pdm_poll.sqs_queue_arn | ||
| event_bus_name = aws_cloudwatch_event_bus.main.name | ||
| } |
10 changes: 10 additions & 0 deletions
10
infrastructure/terraform/components/dl/lambda_event_source_mapping_pdm_poll_lambda.tf
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,10 @@ | ||
| resource "aws_lambda_event_source_mapping" "pdm_poll_lambda" { | ||
| event_source_arn = module.sqs_pdm_poll.sqs_queue_arn | ||
| function_name = module.pdm_poll.function_name | ||
| batch_size = var.queue_batch_size | ||
| maximum_batching_window_in_seconds = var.queue_batch_window_seconds | ||
|
|
||
| function_response_types = [ | ||
| "ReportBatchItemFailures" | ||
| ] | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
103 changes: 103 additions & 0 deletions
103
infrastructure/terraform/components/dl/module_lambda_pdm_poll.tf
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,103 @@ | ||
| module "pdm_poll" { | ||
| source = "https://github.com/NHSDigital/nhs-notify-shared-modules/releases/download/v2.0.24/terraform-lambda.zip" | ||
|
Ian-Hodges marked this conversation as resolved.
Outdated
|
||
|
|
||
| function_name = "pdm-poll" | ||
| description = "A function for polling PDM document status" | ||
|
|
||
| aws_account_id = var.aws_account_id | ||
| component = local.component | ||
| environment = var.environment | ||
| project = var.project | ||
| region = var.region | ||
| group = var.group | ||
|
|
||
| log_retention_in_days = var.log_retention_in_days | ||
| kms_key_arn = module.kms.key_arn | ||
|
|
||
| iam_policy_document = { | ||
| body = data.aws_iam_policy_document.pdm_poll_lambda.json | ||
| } | ||
|
|
||
| function_s3_bucket = local.acct.s3_buckets["lambda_function_artefacts"]["id"] | ||
| function_code_base_path = local.aws_lambda_functions_dir_path | ||
| function_code_dir = "pdm-poll-lambda/dist" | ||
| function_include_common = true | ||
| handler_function_name = "handler" | ||
| runtime = "nodejs22.x" | ||
| memory = 128 | ||
| timeout = 60 | ||
| log_level = var.log_level | ||
|
|
||
| force_lambda_code_deploy = var.force_lambda_code_deploy | ||
| enable_lambda_insights = false | ||
|
|
||
| send_to_firehose = true | ||
|
Ian-Hodges marked this conversation as resolved.
Outdated
|
||
| log_destination_arn = local.log_destination_arn | ||
| log_subscription_role_arn = local.acct.log_subscription_role_arn | ||
|
|
||
| lambda_env_vars = { | ||
| "APIM_BASE_URL" = local.deploy_pdm_mock ? aws_api_gateway_stage.pdm_mock[0].invoke_url : var.apim_base_url | ||
| "APIM_ACCESS_TOKEN_SSM_PARAMETER_NAME" = local.apim_access_token_ssm_parameter_name | ||
| "EVENT_PUBLISHER_EVENT_BUS_ARN" = aws_cloudwatch_event_bus.main.arn | ||
| "EVENT_PUBLISHER_DLQ_URL" = module.sqs_event_publisher_errors.sqs_queue_url | ||
| "POLL_MAX_RETRIES" = 10 | ||
| } | ||
| } | ||
|
|
||
| data "aws_iam_policy_document" "pdm_poll_lambda" { | ||
| statement { | ||
| sid = "AllowSSMParam" | ||
| effect = "Allow" | ||
|
|
||
| actions = [ | ||
| "ssm:GetParameter", | ||
| "ssm:GetParameters", | ||
| "ssm:GetParametersByPath" | ||
| ] | ||
|
|
||
| resources = [ | ||
| "arn:aws:ssm:${var.region}:${var.aws_account_id}:parameter/${var.component}/${var.environment}/apim/*" | ||
| ] | ||
| } | ||
| statement { | ||
| sid = "PutEvents" | ||
| effect = "Allow" | ||
|
|
||
| actions = [ | ||
| "events:PutEvents", | ||
| ] | ||
|
|
||
| resources = [ | ||
| aws_cloudwatch_event_bus.main.arn, | ||
| ] | ||
| } | ||
|
|
||
| statement { | ||
| sid = "SQSPermissionsDLQs" | ||
| effect = "Allow" | ||
|
|
||
| actions = [ | ||
| "sqs:SendMessage", | ||
| "sqs:SendMessageBatch", | ||
| ] | ||
|
|
||
| resources = [ | ||
| module.sqs_event_publisher_errors.sqs_queue_arn, | ||
| ] | ||
| } | ||
| statement { | ||
| sid = "SQSPermissionsPollPdmQueue" | ||
| effect = "Allow" | ||
|
|
||
| actions = [ | ||
| "sqs:ReceiveMessage", | ||
| "sqs:DeleteMessage", | ||
| "sqs:GetQueueAttributes", | ||
| "sqs:GetQueueUrl", | ||
| ] | ||
|
|
||
| resources = [ | ||
| module.sqs_pdm_poll.sqs_queue_arn, | ||
| ] | ||
| } | ||
| } | ||
35 changes: 35 additions & 0 deletions
35
infrastructure/terraform/components/dl/module_sqs_pdm_poll.tf
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,35 @@ | ||
| module "sqs_pdm_poll" { | ||
| source = "https://github.com/NHSDigital/nhs-notify-shared-modules/releases/download/v2.0.24/terraform-sqs.zip" | ||
|
|
||
| aws_account_id = var.aws_account_id | ||
| component = local.component | ||
| environment = var.environment | ||
| project = var.project | ||
| region = var.region | ||
| name = "pdm-poll" | ||
| sqs_kms_key_arn = module.kms.key_arn | ||
| visibility_timeout_seconds = 60 | ||
| delay_seconds = 5 | ||
| create_dlq = true | ||
| sqs_policy_overload = data.aws_iam_policy_document.sqs_pdm_poll.json | ||
| } | ||
|
|
||
| data "aws_iam_policy_document" "sqs_pdm_poll" { | ||
| statement { | ||
| sid = "AllowEventBridgeToSendMessage" | ||
| effect = "Allow" | ||
|
|
||
| principals { | ||
| type = "Service" | ||
| identifiers = ["events.amazonaws.com"] | ||
| } | ||
|
|
||
| actions = [ | ||
| "sqs:SendMessage" | ||
| ] | ||
|
|
||
| resources = [ | ||
| "arn:aws:sqs:${var.region}:${var.aws_account_id}:${local.csi}-pdm-poll-queue" | ||
| ] | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.