Skip to content

Commit cfcdfef

Browse files
add README with instructions on the supplier-mock lambda
1 parent 994de51 commit cfcdfef

3 files changed

Lines changed: 37 additions & 9 deletions

File tree

infrastructure/terraform/components/api/module_lambda_supplier_mock.tf

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -39,12 +39,13 @@ module "supplier_mock" {
3939
ENVIRONMENT = var.environment
4040
GET_LETTERS_FUNCTION_NAME = module.get_letters.function_name
4141
PATCH_LETTER_FUNCTION_NAME = module.patch_letter.function_name
42-
SUPPLIER_MOCK_GET_LETTERS_LIMIT_PARAM_NAME = aws_ssm_parameter.supplier_mock_get_letters_limit.name
43-
SUPPLIER_MOCK_SUPPLIER_ID = aws_ssm_parameter.supplier_mock_supplier_id.name
42+
SUPPLIER_MOCK_GET_LETTERS_LIMIT_PARAM_NAME = aws_ssm_parameter.supplier_mock_get_letters_limit[0].name
43+
SUPPLIER_MOCK_SUPPLIER_ID = aws_ssm_parameter.supplier_mock_supplier_id[0].name
4444
})
4545
}
4646

4747
resource "aws_ssm_parameter" "supplier_mock_get_letters_limit" {
48+
count = var.deploy_supplier_mock_scheduler ? 1 : 0
4849
name = format("/nhs/supapi/supplier-mock/%s/get-letters-limit", var.environment)
4950
description = "Default get_letters limit for supplier mock lambda"
5051
type = "String"
@@ -56,6 +57,7 @@ resource "aws_ssm_parameter" "supplier_mock_get_letters_limit" {
5657
}
5758

5859
resource "aws_ssm_parameter" "supplier_mock_supplier_id" {
60+
count = var.deploy_supplier_mock_scheduler ? 1 : 0
5961
name = format("/nhs/supapi/supplier-mock/%s/supplier-id", var.environment)
6062
description = "Supplier ID to be used by the supplier mock lambda"
6163
type = "String"
@@ -104,8 +106,8 @@ data "aws_iam_policy_document" "supplier_mock_lambda" {
104106
]
105107

106108
resources = [
107-
aws_ssm_parameter.supplier_mock_get_letters_limit.arn,
108-
aws_ssm_parameter.supplier_mock_supplier_id.arn
109+
aws_ssm_parameter.supplier_mock_get_letters_limit[0].arn,
110+
aws_ssm_parameter.supplier_mock_supplier_id[0].arn
109111
]
110112
}
111113
}

lambdas/supplier-mock/README.md

Lines changed: 26 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,30 @@
11
<!-- vale off -->
22

3-
# header to satisfy markdown format
3+
# Supplier Mock
4+
5+
## What is does
6+
7+
The supplier-mock lambda simulates the supplier's system behaviour so that downstream services can simulate supplier interaction without relying on a live supplier system.
8+
The mock simulates the journey of a letter with the Supplier. It utilises the api-handler and retrieves pending letters by calling the `getLetters` lambda directly and then provides status updates for each letter by calling the `patchLetter` lambda.
9+
Each time the mock is called it will call `getLetters` once with for the **supplierId** `TestSupplier1` and with a **limit** of `100` letters. These default values can be configured in the AWS Parameter Store as explained in [How to modify parameter store variables](#how-to-modify-default-variable-values-in-parameter-store) . It then loops through each retrieved letter and updates its status by calling `patchLetter`.
10+
11+
## How to deploy the supapi-supplier-mock schedule
12+
13+
The AWS EventBridge Schedule that calls the supplier-mock lambda is created by the terraform file **/infrastructure/terraform/components/api/scheduler_supplier_mock.tf**, however, by default it's not deployed as it's not needed by every dynamic environment.
14+
If you need to deploy the schedule in your environment you need to set the variable `deploy_supplier_mock_scheduler = true` in the file **/infrastructure/terraform/components/api/variables.tf**.
15+
16+
## How to run the lambda
17+
18+
The supplier-mock lambda can be activated by manually enabling the `{environment}-supapi-supplier-mock` AWS EventBridge schedule from the AWS console. The schedule is configured to call the lambda once per minute. You need to manually disable the schedule from the AWS console to stop calling the supplier-mock lambda.
19+
**NOTE: The schedule is not deployed by default**
20+
21+
## How to modify default variable values in parameter store
22+
23+
As mentioned above the `limit` and `supplierId` default values are stored in the AWS Parameter Store and can be modified if needed by accessing the Parameter Store from the AWS Console. These store parameters are created in the **/infrastructure/terraform/components/api/module_lambda_supplier_mock.tf** module, but only if the `deploy_supplier_mock_scheduler` variable is set to `true`. The parameters are:
24+
25+
| Parameter | default value |
26+
| --------------------------------------------------------- | ------------- |
27+
| /nhs/supapi/supplier-mock/{environment}/get-letters-limit | 100 |
28+
| /nhs/supapi/supplier-mock/{environment}/supplier-id | TestSupplier1 |
429

5-
1. explain what the lambda does
6-
2. how to deploy the lambda and scheduler
7-
3. how to enable the scheduler.
8-
4. describe how to modify the "limit" and "supplierId" parameters
930
<!-- vale on -->

lambdas/supplier-mock/src/supplier-mock.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,11 @@ async function callPatchLetter(
3232
): Promise<void> {
3333
for (const letter of letters) {
3434
let patchInvokeResponse;
35+
deps.logger.info({
36+
letterId: letter.id,
37+
letterStatus: letter.attributes?.status,
38+
specificationId: letter.attributes?.specificationId,
39+
});
3540
try {
3641
patchInvokeResponse = await deps.lambdaClient.send(
3742
new InvokeCommand({

0 commit comments

Comments
 (0)