Skip to content

Commit f9e48bc

Browse files
authored
Merge branch 'master' into feature/VED-1098
2 parents 8dc4be7 + 7a2a83a commit f9e48bc

23 files changed

Lines changed: 533 additions & 393 deletions

File tree

infrastructure/account/.terraform.lock.hcl

Lines changed: 16 additions & 16 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

infrastructure/instance/.terraform.lock.hcl

Lines changed: 16 additions & 16 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

infrastructure/instance/modules/mns_publisher/mns_publisher_lambda.tf

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -182,7 +182,7 @@ resource "aws_lambda_function" "mns_publisher_lambda" {
182182
package_type = "Image"
183183
image_uri = module.mns_publisher_docker_image.image_uri
184184
architectures = ["x86_64"]
185-
timeout = 120
185+
timeout = 300
186186

187187
vpc_config {
188188
subnet_ids = var.private_subnet_ids

infrastructure/instance/modules/mns_publisher/sqs_mns_outbound_events.tf

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ resource "aws_sqs_queue" "mns_outbound_events" {
22
name = "${var.mns_publisher_resource_name_prefix}-queue"
33
fifo_queue = false
44
kms_master_key_id = aws_kms_key.mns_outbound_events.arn
5-
visibility_timeout_seconds = 180
5+
visibility_timeout_seconds = 450
66
redrive_policy = jsonencode({
77
deadLetterTargetArn = aws_sqs_queue.mns_outbound_events_dlq.arn
88
maxReceiveCount = 2

infrastructure/instance/policies/secret_manager.json

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,10 @@
44
{
55
"Effect": "Allow",
66
"Action": "secretsmanager:GetSecretValue",
7-
"Resource": "arn:aws:secretsmanager:eu-west-2:${account_id}:secret:imms/outbound/*/*"
7+
"Resource": [
8+
"arn:aws:secretsmanager:eu-west-2:${account_id}:secret:imms/outbound/*/*",
9+
"arn:aws:secretsmanager:eu-west-2:${account_id}:secret:imms/pds/*/*"
10+
]
811
}
912
]
1013
}

infrastructure/instance/sqs_id_sync.tf

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
resource "aws_sqs_queue" "id_sync_queue" {
22
name = "imms-${local.resource_scope}-id-sync-queue"
33
kms_master_key_id = data.aws_kms_key.existing_id_sync_sqs_encryption_key.arn
4-
visibility_timeout_seconds = 360
4+
visibility_timeout_seconds = 1080 # as per AWS docs to be 6 times the Lambda function timeout but kept to 3 times
55
redrive_policy = jsonencode({
66
deadLetterTargetArn = aws_sqs_queue.id_sync_dlq.arn
77
maxReceiveCount = 4

lambdas/delta_backend/src/observability.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,5 @@
2828
level=os.environ.get("LOG_LEVEL", "INFO"),
2929
# Serialise uncaught exceptions as structured JSON.
3030
log_uncaught_exceptions=True,
31-
# Set POWERTOOLS_LOGGER_LOG_CALLABLE_LOCATION=true to re-enable locally.
32-
location=os.environ.get("POWERTOOLS_LOGGER_LOG_CALLABLE_LOCATION", "false").lower() == "true",
31+
location=False,
3332
)

lambdas/id_sync/src/id_sync.py

Lines changed: 25 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,15 @@
11
"""
2-
- Parses the incoming AWS event into `AwsLambdaEvent` and iterate its `records`.
3-
- Delegate each record to `process_record` and collect `nhs_number` from each result.
4-
- If any record has status == "error" raise `IdSyncException` with aggregated nhs_numbers.
5-
- Any unexpected error is wrapped into `IdSyncException(message="Error processing id_sync event")`.
2+
- Parses the incoming AWS event into `AwsLambdaEvent` and iterates its `records`.
3+
- Delegates each record to `process_record` with per-record exception isolation.
4+
- Returns {"batchItemFailures": [...]} for any failed records so SQS only re-drives the failing messages.
5+
- A handler-level exception (bad event schema etc.) re-raises to trigger full batch retry.
66
"""
77

88
from typing import Any
99

1010
from common.aws_lambda_event import AwsLambdaEvent
1111
from common.clients import STREAM_NAME, logger
1212
from common.log_decorator import logging_decorator
13-
from exceptions.id_sync_exception import IdSyncException
1413
from record_processor import process_record
1514

1615

@@ -25,28 +24,32 @@ def handler(event_data: dict[str, Any], _context) -> dict[str, Any]:
2524

2625
logger.info("id_sync processing event with %d records", len(records))
2726

28-
error_count = 0
27+
batch_item_failures = []
2928

3029
for record in records:
31-
result = process_record(record)
32-
33-
if result.get("status") == "error":
34-
error_count += 1
35-
36-
if error_count > 0:
37-
raise IdSyncException(
38-
message=f"Processed {len(records)} records with {error_count} errors",
39-
)
30+
try:
31+
result = process_record(record)
32+
if result.get("status") == "error":
33+
message_id = record.get("messageId")
34+
logger.error(
35+
"id_sync record processing failed for messageId: %s — %s",
36+
message_id,
37+
result.get("message"),
38+
)
39+
batch_item_failures.append({"itemIdentifier": message_id})
40+
except Exception:
41+
message_id = record.get("messageId")
42+
logger.exception("Unexpected error processing messageId: %s", message_id)
43+
batch_item_failures.append({"itemIdentifier": message_id})
44+
45+
if batch_item_failures:
46+
logger.error("id_sync completed with %d/%d failures", len(batch_item_failures), len(records))
47+
return {"batchItemFailures": batch_item_failures}
4048

4149
response = {"status": "success", "message": f"Successfully processed {len(records)} records"}
42-
4350
logger.info("id_sync handler completed: %s", response)
4451
return response
4552

46-
except IdSyncException as e:
47-
logger.exception(f"id_sync error: {e.message}")
48-
raise
4953
except Exception:
50-
msg = "Error processing id_sync event"
51-
logger.exception(msg)
52-
raise IdSyncException(message=msg)
54+
logger.exception("Unexpected error processing id_sync event")
55+
raise

0 commit comments

Comments
 (0)