1+ from datetime import datetime
2+
13from aws_cdk import CfnOutput , Duration , RemovalPolicy , aws_apigateway
24from aws_cdk import aws_dynamodb as dynamodb
35from aws_cdk import aws_iam as iam
46from aws_cdk import aws_lambda as _lambda
5- from aws_cdk import aws_logs
67from aws_cdk .aws_lambda_python_alpha import PythonLayerVersion
8+ from aws_cdk .aws_logs import LogGroup , RetentionDays
79from constructs import Construct
810from my_service .api_db_construct import ApiDbConstruct # type: ignore
911
@@ -14,7 +16,7 @@ class ApiConstruct(Construct):
1416
1517 def __init__ (self , scope : Construct , id_ : str , appconfig_app_name : str ) -> None :
1618 super ().__init__ (scope , id_ )
17-
19+ self . id_ = id_
1820 self .api_db = ApiDbConstruct (self , f'{ id_ } db' )
1921 self .lambda_role = self ._build_lambda_role (self .api_db .db )
2022 self .common_layer = self ._build_common_layer ()
@@ -71,7 +73,7 @@ def _build_common_layer(self) -> PythonLayerVersion:
7173 def _add_post_lambda_integration (self , api_name : aws_apigateway .Resource , role : iam .Role , db : dynamodb .Table , appconfig_app_name : str ):
7274 lambda_function = _lambda .Function (
7375 self ,
74- constants .SERVICE_ROLE ,
76+ constants .CREATE_LAMBDA ,
7577 runtime = _lambda .Runtime .PYTHON_3_9 ,
7678 code = _lambda .Code .from_asset (constants .BUILD_FOLDER ),
7779 handler = 'service.handlers.create_order.create_order' ,
@@ -92,7 +94,13 @@ def _add_post_lambda_integration(self, api_name: aws_apigateway.Resource, role:
9294 memory_size = constants .API_HANDLER_LAMBDA_MEMORY_SIZE ,
9395 layers = [self .common_layer ],
9496 role = role ,
95- log_retention = aws_logs .RetentionDays .ONE_DAY ,
97+ )
98+
99+ LogGroup (
100+ self ,
101+ f'{ self .id_ } constants.CREATE_LAMBDA-{ datetime .now ()} ' ,
102+ removal_policy = RemovalPolicy .DESTROY ,
103+ retention = RetentionDays .ONE_DAY ,
96104 )
97105
98106 # POST /api/orders/
0 commit comments