Skip to content

Commit 806ab90

Browse files
committed
[PRMP-1048] handler
1 parent a993ea8 commit 806ab90

File tree

3 files changed

+88
-0
lines changed

3 files changed

+88
-0
lines changed

.github/workflows/base-lambdas-reusable-deploy-all.yml

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -780,3 +780,17 @@ jobs:
780780
lambda_layer_names: "core_lambda_layer"
781781
secrets:
782782
AWS_ASSUME_ROLE: ${{ secrets.AWS_ASSUME_ROLE }}
783+
784+
deploy_concurrency_controller_lambda:
785+
name: Deploy Concurrency Controller Lambda
786+
uses: ./.github/workflows/base-lambdas-reusable-deploy.yml
787+
with:
788+
environment: ${{ inputs.environment }}
789+
python_version: ${{ inputs.python_version }}
790+
build_branch: ${{ inputs.build_branch }}
791+
sandbox: ${{ inputs.sandbox }}
792+
lambda_handler_name: concurrency_controller_handler
793+
lambda_aws_name: ConcurrencyController
794+
lambda_layer_names: "core_lambda_layer"
795+
secrets:
796+
AWS_ASSUME_ROLE: ${{ secrets.AWS_ASSUME_ROLE }}
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
from services.concurrency_controller_service import ConcurrencyControllerService
2+
from utils.audit_logging_setup import LoggingService
3+
from utils.decorators.handle_lambda_exceptions import handle_lambda_exceptions
4+
from utils.decorators.override_error_check import override_error_check
5+
from utils.decorators.set_audit_arg import set_request_context_for_logging
6+
7+
logger = LoggingService(__name__)
8+
9+
10+
def validate_event(event):
11+
target_function = event.get("targetFunction")
12+
reserved_concurrency = event.get("reservedConcurrency")
13+
14+
if not target_function:
15+
logger.error("Missing required parameter: targetFunction")
16+
raise ValueError("targetFunction is required")
17+
18+
if reserved_concurrency is None:
19+
logger.error("Missing required parameter: reservedConcurrency")
20+
raise ValueError("reservedConcurrency is required")
21+
22+
return target_function, reserved_concurrency
23+
24+
25+
@set_request_context_for_logging
26+
@override_error_check
27+
@handle_lambda_exceptions
28+
def lambda_handler(event, _context):
29+
target_function, reserved_concurrency = validate_event(event)
30+
31+
service = ConcurrencyControllerService()
32+
return service.update_function_concurrency(target_function, reserved_concurrency)
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
import boto3
2+
from utils.audit_logging_setup import LoggingService
3+
4+
logger = LoggingService(__name__)
5+
6+
7+
class ConcurrencyControllerService:
8+
def __init__(self):
9+
self.lambda_client = boto3.client("lambda")
10+
11+
def update_function_concurrency(self, target_function, reserved_concurrency):
12+
logger.info(
13+
f"Updating reserved concurrency for function '{target_function}' to {reserved_concurrency}"
14+
)
15+
16+
try:
17+
response = self.lambda_client.put_function_concurrency(
18+
FunctionName=target_function,
19+
ReservedConcurrentExecutions=reserved_concurrency
20+
)
21+
22+
updated_concurrency = response.get("ReservedConcurrentExecutions")
23+
24+
logger.info(
25+
f"Successfully updated concurrency for '{target_function}'. "
26+
f"Reserved concurrency set to: {updated_concurrency}"
27+
)
28+
29+
return {
30+
"statusCode": 200,
31+
"body": {
32+
"message": "Concurrency updated successfully",
33+
"function": target_function,
34+
"reservedConcurrency": updated_concurrency
35+
}
36+
}
37+
except self.lambda_client.exceptions.ResourceNotFoundException:
38+
logger.error(f"Lambda function '{target_function}' not found")
39+
raise
40+
except self.lambda_client.exceptions.InvalidParameterValueException as e:
41+
logger.error(f"Invalid concurrency value: {e}")
42+
raise

0 commit comments

Comments
 (0)