Skip to content

Commit d2ee99a

Browse files
committed
fix(approvals_service): Remove unused imports and replace InternalServerError
- Remove unused datetime import and current_date variable calculation - Replace InternalServerError with EnvironmentError for environment variable validation - Simplify error handling for SERVICE_NAMESPACE and CONTRACT_STATUS_TABLE checks - InternalServerError is not appropriate for environment configuration issues that occur at module initialization
1 parent fcd82b1 commit d2ee99a

1 file changed

Lines changed: 2 additions & 8 deletions

File tree

unicorn_approvals/src/approvals_service/contract_status_changed_event_handler.py

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2,20 +2,18 @@
22
# SPDX-License-Identifier: MIT-0
33

44
import os
5-
from datetime import datetime
65

76
import boto3
87
from aws_lambda_powertools.logging import Logger
98
from aws_lambda_powertools.metrics import Metrics
109
from aws_lambda_powertools.tracing import Tracer
11-
from aws_lambda_powertools.event_handler.exceptions import InternalServerError
1210
from schema.unicorn_contracts.contractstatuschanged import AWSEvent, ContractStatusChanged, Marshaller
1311

1412
# Initialise Environment variables
1513
if (SERVICE_NAMESPACE := os.environ.get("SERVICE_NAMESPACE")) is None:
16-
raise InternalServerError("SERVICE_NAMESPACE environment variable is undefined")
14+
raise EnvironmentError("SERVICE_NAMESPACE environment variable is undefined")
1715
if (CONTRACT_STATUS_TABLE := os.environ.get("CONTRACT_STATUS_TABLE")) is None:
18-
raise InternalServerError("CONTRACT_STATUS_TABLE environment variable is undefined")
16+
raise EnvironmentError("CONTRACT_STATUS_TABLE environment variable is undefined")
1917

2018
# Initialise PowerTools
2119
logger: Logger = Logger()
@@ -26,10 +24,6 @@
2624
dynamodb = boto3.resource("dynamodb")
2725
table = dynamodb.Table(CONTRACT_STATUS_TABLE) # type: ignore
2826

29-
# Get current date
30-
now = datetime.now()
31-
current_date = now.strftime("%d/%m/%Y %H:%M:%S")
32-
3327

3428
@logger.inject_lambda_context(log_event=True) # type: ignore
3529
@metrics.log_metrics(capture_cold_start_metric=True) # type: ignore

0 commit comments

Comments
 (0)