12
12
13
13
14
14
class ApiConstruct (Construct ):
15
-
16
15
def __init__ (self , scope : Construct , id_ : str , appconfig_app_name : str ) -> None :
17
16
super ().__init__ (scope , id_ )
18
17
self .id_ = id_
@@ -21,8 +20,9 @@ def __init__(self, scope: Construct, id_: str, appconfig_app_name: str) -> None:
21
20
self .common_layer = self ._build_common_layer ()
22
21
self .rest_api = self ._build_api_gw ()
23
22
api_resource : aws_apigateway .Resource = self .rest_api .root .add_resource ('api' ).add_resource (constants .GW_RESOURCE )
24
- self .create_order_func = self ._add_post_lambda_integration (api_resource , self .lambda_role , self .api_db .db , appconfig_app_name ,
25
- self .api_db .idempotency_db )
23
+ self .create_order_func = self ._add_post_lambda_integration (
24
+ api_resource , self .lambda_role , self .api_db .db , appconfig_app_name , self .api_db .idempotency_db
25
+ )
26
26
self .monitoring = CrudMonitoring (self , id_ , self .rest_api , self .api_db .db , self .api_db .idempotency_db , [self .create_order_func ])
27
27
28
28
def _build_api_gw (self ) -> aws_apigateway .RestApi :
@@ -44,30 +44,33 @@ def _build_lambda_role(self, db: dynamodb.Table, idempotency_table: dynamodb.Tab
44
44
constants .SERVICE_ROLE_ARN ,
45
45
assumed_by = iam .ServicePrincipal ('lambda.amazonaws.com' ),
46
46
inline_policies = {
47
- 'dynamic_configuration' :
48
- iam . PolicyDocument ( statements = [
47
+ 'dynamic_configuration' : iam . PolicyDocument (
48
+ statements = [
49
49
iam .PolicyStatement (
50
50
actions = ['appconfig:GetLatestConfiguration' , 'appconfig:StartConfigurationSession' ],
51
51
resources = ['*' ],
52
52
effect = iam .Effect .ALLOW ,
53
53
)
54
- ]),
55
- 'dynamodb_db' :
56
- iam .PolicyDocument (statements = [
54
+ ]
55
+ ),
56
+ 'dynamodb_db' : iam .PolicyDocument (
57
+ statements = [
57
58
iam .PolicyStatement (
58
59
actions = ['dynamodb:PutItem' , 'dynamodb:GetItem' ],
59
60
resources = [db .table_arn ],
60
61
effect = iam .Effect .ALLOW ,
61
62
)
62
- ]),
63
- 'idempotency_table' :
64
- iam .PolicyDocument (statements = [
63
+ ]
64
+ ),
65
+ 'idempotency_table' : iam .PolicyDocument (
66
+ statements = [
65
67
iam .PolicyStatement (
66
68
actions = ['dynamodb:PutItem' , 'dynamodb:GetItem' , 'dynamodb:UpdateItem' , 'dynamodb:DeleteItem' ],
67
69
resources = [idempotency_table .table_arn ],
68
70
effect = iam .Effect .ALLOW ,
69
71
)
70
- ]),
72
+ ]
73
+ ),
71
74
},
72
75
managed_policies = [
73
76
iam .ManagedPolicy .from_aws_managed_policy_name (managed_policy_name = (f'service-role/{ constants .LAMBDA_BASIC_EXECUTION_ROLE } ' ))
@@ -83,8 +86,9 @@ def _build_common_layer(self) -> PythonLayerVersion:
83
86
removal_policy = RemovalPolicy .DESTROY ,
84
87
)
85
88
86
- def _add_post_lambda_integration (self , api_name : aws_apigateway .Resource , role : iam .Role , db : dynamodb .Table , appconfig_app_name : str ,
87
- idempotency_table : dynamodb .Table ) -> _lambda .Function :
89
+ def _add_post_lambda_integration (
90
+ self , api_name : aws_apigateway .Resource , role : iam .Role , db : dynamodb .Table , appconfig_app_name : str , idempotency_table : dynamodb .Table
91
+ ) -> _lambda .Function :
88
92
lambda_function = _lambda .Function (
89
93
self ,
90
94
constants .CREATE_LAMBDA ,
0 commit comments