generated from NHSDigital/nhs-notify-repository-template
-
Notifications
You must be signed in to change notification settings - Fork 2
CCM-11189: POST MI lambda #199
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 all commits
Commits
Show all changes
13 commits
Select commit
Hold shift + click to select a range
063f89f
CCM-11201 Store MI in DDB
stevebux cb2b3c9
CCM-11189 Lambda to POST management information
stevebux 3973979
Fix capitalisation
stevebux 4005e26
More forgiving timestamp validation
stevebux c5c1ca0
Post-rebase fixes
stevebux 26f15d4
Revert unwanted changes
stevebux 88929e7
Address review comments
stevebux 4206e66
Merge branch 'main' into feature/CCM-11189
stevebux f714894
Fix following merge from main
stevebux f43e04f
Merge branch 'main' into feature/CCM-11189
stevebux 21b0bf5
Added TTL for MI
stevebux 369cb8e
Addressed TF review comments
stevebux ed5d35f
Merge branch 'main' into feature/CCM-11189
stevebux 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
68 changes: 68 additions & 0 deletions
68
infrastructure/terraform/components/api/module_lambda_post_mi.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,68 @@ | ||
| module "post_mi" { | ||
| source = "https://github.com/NHSDigital/nhs-notify-shared-modules/releases/download/v2.0.24/terraform-lambda.zip" | ||
|
|
||
| function_name = "post_mi" | ||
| description = "Add management information" | ||
|
|
||
| aws_account_id = var.aws_account_id | ||
| component = var.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.post_mi_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 = "api-handler/dist" | ||
| function_include_common = true | ||
| handler_function_name = "postMI" | ||
| runtime = "nodejs22.x" | ||
| memory = 128 | ||
| timeout = 5 | ||
| log_level = var.log_level | ||
|
|
||
| force_lambda_code_deploy = var.force_lambda_code_deploy | ||
| enable_lambda_insights = false | ||
|
|
||
| send_to_firehose = true | ||
| log_destination_arn = local.destination_arn | ||
| log_subscription_role_arn = local.acct.log_subscription_role_arn | ||
|
|
||
| lambda_env_vars = merge(local.common_lambda_env_vars, {}) | ||
| } | ||
|
|
||
| data "aws_iam_policy_document" "post_mi_lambda" { | ||
| statement { | ||
| sid = "KMSPermissions" | ||
| effect = "Allow" | ||
|
|
||
| actions = [ | ||
| "kms:Decrypt", | ||
| "kms:GenerateDataKey", | ||
| ] | ||
|
|
||
| resources = [ | ||
| module.kms.key_arn, ## Requires shared kms module | ||
| ] | ||
| } | ||
|
|
||
| statement { | ||
| sid = "AllowDynamoDBAccess" | ||
| effect = "Allow" | ||
|
|
||
| actions = [ | ||
| "dynamodb:PutItem", | ||
| ] | ||
|
|
||
| resources = [ | ||
| aws_dynamodb_table.mi.arn, | ||
| ] | ||
| } | ||
| } |
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,67 @@ | ||
| import { Logger } from "pino"; | ||
| import { setupDynamoDBContainer, createTables, DBContext, deleteTables } from "./db"; | ||
| import { createTestLogger, LogStream } from "./logs"; | ||
| import { MIRepository } from "../mi-repository"; | ||
|
|
||
| // Database tests can take longer, especially with setup and teardown | ||
| jest.setTimeout(30000); | ||
|
|
||
|
|
||
| describe('MiRepository', () => { | ||
| let db: DBContext; | ||
| let miRepository: MIRepository; | ||
| let logStream: LogStream; | ||
| let logger: Logger; | ||
|
|
||
|
|
||
| beforeAll(async () => { | ||
| db = await setupDynamoDBContainer(); | ||
| }); | ||
|
|
||
| beforeEach(async () => { | ||
| await createTables(db); | ||
| ( | ||
| { logStream, logger } = createTestLogger() | ||
| ); | ||
|
|
||
| miRepository = new MIRepository(db.docClient, logger, db.config); | ||
| }); | ||
|
|
||
| afterEach(async () => { | ||
| await deleteTables(db); | ||
| jest.useRealTimers(); | ||
| }); | ||
|
|
||
| afterAll(async () => { | ||
| await db.container.stop(); | ||
| }); | ||
|
|
||
| describe('putMi', () => { | ||
|
|
||
| it('creates a letter with id and timestamps', async () => { | ||
|
|
||
| jest.useFakeTimers(); | ||
| // Month is zero-indexed in JS Date | ||
| jest.setSystemTime(new Date(2020, 1, 1)); | ||
| const mi = { | ||
| specificationId: 'spec1', | ||
| supplierId: 'supplier1', | ||
| groupId:'group1', | ||
| lineItem: 'item1', | ||
| quantity: 12, | ||
| timestamp: new Date().toISOString(), | ||
| stockRemaining: 0 | ||
| }; | ||
|
|
||
| const persistedMi = await(miRepository.putMI(mi)); | ||
|
|
||
| expect(persistedMi).toEqual(expect.objectContaining({ | ||
| id: expect.any(String), | ||
| createdAt: '2020-02-01T00:00:00.000Z', | ||
| updatedAt: '2020-02-01T00:00:00.000Z', | ||
| ttl: 1580518800, // 2020-02-01T00:01:00.000Z, seconds since epoch | ||
| ...mi | ||
| })); | ||
| }); | ||
| }); | ||
| }); |
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,3 +1,4 @@ | ||
| export * from './types'; | ||
| export * from './mi-repository'; | ||
| export * from './letter-repository'; | ||
| export * from './types'; |
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.