Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 9 additions & 1 deletion docs/Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -27,10 +27,14 @@ GEM
erb (4.0.4)
cgi (>= 0.3.3)
eventmachine (1.2.7)
ffi (1.17.2-aarch64-linux-gnu)
ffi (1.17.2-arm64-darwin)
ffi (1.17.2-x86_64-linux-gnu)
forwardable-extended (2.6.0)
gemoji (4.1.0)
google-protobuf (4.31.1-aarch64-linux-gnu)
bigdecimal
rake (>= 13)
google-protobuf (4.31.1-arm64-darwin)
bigdecimal
rake (>= 13)
Expand Down Expand Up @@ -101,8 +105,9 @@ GEM
jekyll-seo-tag (~> 2.1)
minitest (5.24.1)
mutex_m (0.2.0)
nokogiri (1.18.9-arm64-darwin)
nokogiri (1.18.4-aarch64-linux-gnu)
racc (~> 1.4)
nokogiri (1.18.9-arm64-darwin)
nokogiri (1.18.9-x86_64-linux-gnu)
racc (~> 1.4)
pathutil (0.16.2)
Expand All @@ -116,6 +121,8 @@ GEM
rexml (3.4.1)
rouge (4.5.2)
safe_yaml (1.0.5)
sass-embedded (1.83.0-aarch64-linux-gnu)
google-protobuf (~> 4.28)
sass-embedded (1.83.0-arm64-darwin)
google-protobuf (~> 4.28)
sass-embedded (1.83.0-x86_64-linux-gnu)
Expand All @@ -128,6 +135,7 @@ GEM
webrick (1.8.2)

PLATFORMS
aarch64-linux
arm64-darwin-23
x86_64-linux

Expand Down
1 change: 1 addition & 0 deletions infrastructure/terraform/components/api/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ No requirements.
| <a name="module_get_letters"></a> [get\_letters](#module\_get\_letters) | git::https://github.com/NHSDigital/nhs-notify-shared-modules.git//infrastructure/modules/lambda | v2.0.10 |
| <a name="module_hello_world"></a> [hello\_world](#module\_hello\_world) | git::https://github.com/NHSDigital/nhs-notify-shared-modules.git//infrastructure/modules/lambda | v2.0.10 |
| <a name="module_kms"></a> [kms](#module\_kms) | git::https://github.com/NHSDigital/nhs-notify-shared-modules.git//infrastructure/modules/kms | v2.0.10 |
| <a name="module_patch_letters"></a> [patch\_letters](#module\_patch\_letters) | git::https://github.com/NHSDigital/nhs-notify-shared-modules.git//infrastructure/modules/lambda | v2.0.10 |
## Outputs

| Name | Description |
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ data "aws_iam_policy_document" "api_gateway_execution_policy" {
module.authorizer_lambda.function_arn,
module.hello_world.function_arn,
module.get_letters.function_arn,
module.patch_letters.function_arn
]
}
}
1 change: 1 addition & 0 deletions infrastructure/terraform/components/api/locals.tf
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ locals {
AUTHORIZER_LAMBDA_ARN = module.authorizer_lambda.function_arn
HELLO_WORLD_LAMBDA_ARN = module.hello_world.function_arn
GET_LETTERS_LAMBDA_ARN = module.get_letters.function_arn
PATCH_LETTERS_LAMBDA_ARN = module.patch_letters.function_arn
})

destination_arn = "arn:aws:logs:${var.region}:${var.shared_infra_account_id}:destination:nhs-main-obs-firehose-logs"
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
module "patch_letters" {
source = "git::https://github.com/NHSDigital/nhs-notify-shared-modules.git//infrastructure/modules/lambda?ref=v2.0.10"

function_name = "patch_letters"
description = "Update the status of a letter"

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.patch_letters_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 = "patchLetters"
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 = {
}
}

data "aws_iam_policy_document" "patch_letters_lambda" {
statement {
sid = "KMSPermissions"
effect = "Allow"

actions = [
"kms:Decrypt",
"kms:GenerateDataKey",
]

resources = [
module.kms.key_arn, ## Requires shared kms module
]
}
}
168 changes: 158 additions & 10 deletions infrastructure/terraform/components/api/resources/spec.tmpl.json
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,9 @@
},
"openapi": "3.0.1",
"paths": {
"/": {
"/letters": {
"get": {
"description": "Returns 200 OK if the API is up.",
"description": "Returns 200 OK with paginated letter ids.",
"responses": {
"200": {
"description": "OK"
Expand All @@ -36,7 +36,7 @@
"LambdaAuthorizer": []
}
],
"summary": "Health check",
"summary": "Get letters",
"x-amazon-apigateway-integration": {
"contentHandling": "CONVERT_TO_TEXT",
"credentials": "${APIG_EXECUTION_ROLE_ARN}",
Expand All @@ -49,24 +49,172 @@
},
"timeoutInMillis": 29000,
"type": "AWS_PROXY",
"uri": "arn:aws:apigateway:${AWS_REGION}:lambda:path/2015-03-31/functions/${HELLO_WORLD_LAMBDA_ARN}/invocations"
"uri": "arn:aws:apigateway:${AWS_REGION}:lambda:path/2015-03-31/functions/${GET_LETTERS_LAMBDA_ARN}/invocations"
}
}
},
"/letters": {
"get": {
"description": "Returns 200 OK with paginated letter ids.",
"/letters/{id}": {
"parameters": [
{
"description": "Unique identifier of this resource",
"in": "path",
"name": "id",
"required": true,
"schema": {
"type": "string"
}
}
],
"patch": {
"description": "Update the status of a letter by providing the new status in the request body.",
"requestBody": {
"content": {
"application/vnd.api+json": {
"schema": {
"properties": {
"data": {
"properties": {
"attributes": {
"properties": {
"reasonCode": {
"description": "Reason code for the given status",
"type": "number"
},
"reasonText": {
"description": "Reason text for the given status",
"type": "string"
},
"requestedProductionStatus": {
"description": "The requested production status for this letter.\nMay only be set by NHS Notify.",
"enum": [
"ACTIVE",
"HOLD",
"CANCEL"
],
"title": "ProductionStatus",
"type": "string"
},
"status": {
"default": "PENDING",
"description": "The supplier status of an individual letter",
"enum": [
"PENDING",
"ACCEPTED",
"REJECTED",
"PRINTED",
"ENCLOSED",
"CANCELLED",
"DISPATCHED",
"FAILED",
"RETURNED",
"DESTROYED",
"FORWARDED"
],
"type": "string"
}
},
"type": "object"
},
"id": {
"type": "string"
},
"type": {
"const": "Letter",
"type": "string"
}
},
"type": "object"
}
},
"type": "object"
}
}
},
"required": true
},
"responses": {
"200": {
"description": "OK"
"content": {
"application/vnd.api+json": {
"schema": {
"properties": {
"data": {
"properties": {
"attributes": {
"properties": {
"reasonCode": {
"description": "Reason code for the given status",
"type": "number"
},
"reasonText": {
"description": "Reason text for the given status",
"type": "string"
},
"requestedProductionStatus": {
"description": "A requested status for the production of a letter",
"enum": [
"ACTIVE",
"HOLD",
"CANCEL"
],
"title": "ProductionStatus",
"type": "string"
},
"status": {
"default": "PENDING",
"description": "The supplier status of an individual letter",
"enum": [
"PENDING",
"ACCEPTED",
"REJECTED",
"PRINTED",
"ENCLOSED",
"CANCELLED",
"DISPATCHED",
"FAILED",
"RETURNED",
"DESTROYED",
"FORWARDED"
],
"type": "string"
}
},
"required": [
"status",
"requestedProductionStatus"
],
"type": "object"
},
"id": {
"type": "string"
},
"type": {
"const": "Letter",
"type": "string"
}
},
"type": "object"
}
},
"type": "object"
}
}
},
"description": "Letter resource updated successfully"
},
"400": {
"description": "Bad request"
},
"404": {
"description": "Resource not found"
}
},
"security": [
{
"LambdaAuthorizer": []
}
],
"summary": "Get letters",
"summary": "Update the status of a letter",
"x-amazon-apigateway-integration": {
"contentHandling": "CONVERT_TO_TEXT",
"credentials": "${APIG_EXECUTION_ROLE_ARN}",
Expand All @@ -79,7 +227,7 @@
},
"timeoutInMillis": 29000,
"type": "AWS_PROXY",
"uri": "arn:aws:apigateway:${AWS_REGION}:lambda:path/2015-03-31/functions/${GET_LETTERS_LAMBDA_ARN}/invocations"
"uri": "arn:aws:apigateway:${AWS_REGION}:lambda:path/2015-03-31/functions/${PATCH_LETTERS_LAMBDA_ARN}/invocations"
}
}
}
Expand Down
Loading
Loading