Skip to content

Commit e0d4062

Browse files
author
Ran Isenberg
committed
a
1 parent 19453f7 commit e0d4062

File tree

10 files changed

+366
-256
lines changed

10 files changed

+366
-256
lines changed

.pre-commit-config.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ repos:
2626
exclude: "^(?!helpers/)"
2727
- repo: https://github.com/astral-sh/ruff-pre-commit
2828
# Ruff version.
29-
rev: v0.1.13
29+
rev: v0.1.14
3030
hooks:
3131
# Run the Ruff linter.
3232
- id: ruff

cdk/service/api_construct.py

Lines changed: 14 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -25,25 +25,26 @@ def __init__(self, scope: Construct, id_: str, appconfig_app_name: str, is_produ
2525
self.create_order_func = self._add_post_lambda_integration(
2626
orders_resource, self.lambda_role, self.api_db.db, appconfig_app_name, self.api_db.idempotency_db
2727
)
28-
29-
# GET /swagger
30-
swagger_resource: aws_apigateway.Resource = self.rest_api.root.add_resource(constants.SWAGGER_RESOURCE)
31-
swagger_resource.add_method(http_method='GET', integration=aws_apigateway.LambdaIntegration(handler=self.create_order_func))
32-
# GET /swagger.css
33-
swagger_resource_css = self.rest_api.root.add_resource(constants.SWAGGER_CSS_RESOURCE)
34-
swagger_resource_css.add_method(http_method='GET', integration=aws_apigateway.LambdaIntegration(handler=self.create_order_func))
35-
# GET /swagger.js
36-
swagger_resource_js = self.rest_api.root.add_resource(constants.SWAGGER_JS_RESOURCE)
37-
swagger_resource_js.add_method(http_method='GET', integration=aws_apigateway.LambdaIntegration(handler=self.create_order_func))
38-
39-
CfnOutput(self, id=constants.SWAGGER_URL, value=f'{self.rest_api.url}swagger').override_logical_id(constants.SWAGGER_URL)
40-
28+
self._build_swagger_endpoints(rest_api=self.rest_api, dest_func=self.create_order_func)
4129
self.monitoring = CrudMonitoring(self, id_, self.rest_api, self.api_db.db, self.api_db.idempotency_db, [self.create_order_func])
4230

4331
if is_production_env:
4432
# add WAF
4533
self.waf = WafToApiGatewayConstruct(self, f'{id_}waf', self.rest_api)
4634

35+
def _build_swagger_endpoints(self, rest_api: aws_apigateway.RestApi, dest_func: _lambda.Function) -> None:
36+
# GET /swagger
37+
swagger_resource: aws_apigateway.Resource = rest_api.root.add_resource(constants.SWAGGER_RESOURCE)
38+
swagger_resource.add_method(http_method='GET', integration=aws_apigateway.LambdaIntegration(handler=dest_func))
39+
# GET /swagger.css
40+
swagger_resource_css = rest_api.root.add_resource(constants.SWAGGER_CSS_RESOURCE)
41+
swagger_resource_css.add_method(http_method='GET', integration=aws_apigateway.LambdaIntegration(handler=dest_func))
42+
# GET /swagger.js
43+
swagger_resource_js = rest_api.root.add_resource(constants.SWAGGER_JS_RESOURCE)
44+
swagger_resource_js.add_method(http_method='GET', integration=aws_apigateway.LambdaIntegration(handler=dest_func))
45+
46+
CfnOutput(self, id=constants.SWAGGER_URL, value=f'{rest_api.url}swagger').override_logical_id(constants.SWAGGER_URL)
47+
4748
def _build_api_gw(self) -> aws_apigateway.RestApi:
4849
rest_api: aws_apigateway.RestApi = aws_apigateway.RestApi(
4950
self,

cdk/service/configuration/configuration_construct.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,14 +29,14 @@ def __init__(self, scope: Construct, id_: str, environment: str, service_name: s
2929
self.config_app = appconfig.Application(
3030
self,
3131
id=self.app_name,
32-
name=self.app_name,
32+
application_name=self.app_name,
3333
)
3434

3535
self.config_env = appconfig.Environment(
3636
self,
3737
id=f'{id_}env',
3838
application=self.config_app,
39-
name=environment,
39+
environment_name=environment,
4040
)
4141

4242
# zero minutes, zero bake, 100 growth all at once

docs/swagger/openapi.json

Lines changed: 179 additions & 100 deletions
Original file line numberDiff line numberDiff line change
@@ -1,117 +1,196 @@
11
{
22
"openapi": "3.0.0",
33
"info": {
4-
"title": "AWS Lambda Handler Cookbook",
5-
"version": "1.0.0"
4+
"title": "AWS Lambda Handler Cookbook - Orders Service",
5+
"version": "1.0.0"
66
},
77
"servers": [
8-
{
9-
"url": "/prod"
10-
}
8+
{
9+
"url": "/prod"
10+
}
1111
],
1212
"paths": {
13-
"/api/orders": {
14-
"post": {
15-
"tags": [
16-
"CRUD"
17-
],
18-
"summary": "Create an order",
19-
"description": "Create an order identified by the body payload`",
20-
"operationId": "handle_create_order_api_orders_post",
21-
"requestBody": {
22-
"content": {
23-
"application/json": {
24-
"schema": {
25-
"$ref": "#/components/schemas/CreateOrderRequest"
26-
}
27-
}
28-
},
29-
"required": true
30-
},
31-
"responses": {
32-
"200": {
33-
"description": "The created order",
34-
"content": {
35-
"application/json": {
36-
"schema": {
37-
"$ref": "#/components/schemas/CreateOrderOutput"
38-
}
39-
}
40-
}
41-
},
42-
"501": {
43-
"description": "internal server error",
44-
"content": {
45-
"application/json": {
46-
"schema": {
47-
"properties": {
48-
"error": {
49-
"type": "string",
50-
"title": "Error",
51-
"default": "internal server error"
52-
}
53-
},
54-
"type": "object",
55-
"title": "InternalServerErrorOutput"
56-
}
57-
}
58-
}
59-
}
13+
"/api/orders": {
14+
"post": {
15+
"tags": [
16+
"CRUD"
17+
],
18+
"summary": "Create an order",
19+
"description": "Create an order identified by the body payload",
20+
"operationId": "handle_create_order_api_orders_post",
21+
"requestBody": {
22+
"content": {
23+
"application/json": {
24+
"schema": {
25+
"$ref": "#/components/schemas/CreateOrderRequest"
6026
}
27+
}
28+
},
29+
"required": true
30+
},
31+
"responses": {
32+
"200": {
33+
"description": "The created order",
34+
"content": {
35+
"application/json": {
36+
"schema": {
37+
"$ref": "#/components/schemas/CreateOrderOutput"
38+
}
39+
}
40+
}
41+
},
42+
"442": {
43+
"description": "Invalid create order request",
44+
"content": {
45+
"application/json": {
46+
"schema": {
47+
"$ref": "#/components/schemas/InvalidRestApiRequest"
48+
}
49+
}
50+
}
51+
},
52+
"501": {
53+
"description": "Internal server error",
54+
"content": {
55+
"application/json": {
56+
"schema": {
57+
"$ref": "#/components/schemas/InternalServerErrorOutput"
58+
}
59+
}
60+
}
6161
}
62+
}
6263
}
64+
}
6365
},
6466
"components": {
65-
"schemas": {
66-
"CreateOrderOutput": {
67-
"properties": {
68-
"name": {
69-
"type": "string",
70-
"maxLength": 20,
71-
"minLength": 1,
72-
"title": "Name"
73-
},
74-
"item_count": {
75-
"type": "integer",
76-
"exclusiveMinimum": 0,
77-
"title": "Item Count"
78-
},
79-
"id": {
80-
"type": "string",
81-
"maxLength": 36,
82-
"minLength": 36,
83-
"title": "Id"
84-
}
85-
},
86-
"type": "object",
87-
"required": [
88-
"name",
89-
"item_count",
90-
"id"
91-
],
92-
"title": "CreateOrderOutput"
67+
"schemas": {
68+
"CreateOrderOutput": {
69+
"properties": {
70+
"name": {
71+
"type": "string",
72+
"maxLength": 20,
73+
"minLength": 1,
74+
"title": "Name",
75+
"description": "Customer name"
9376
},
94-
"CreateOrderRequest": {
95-
"properties": {
96-
"customer_name": {
97-
"type": "string",
98-
"maxLength": 20,
99-
"minLength": 1,
100-
"title": "Customer Name"
101-
},
102-
"order_item_count": {
103-
"type": "integer",
104-
"exclusiveMinimum": 0,
105-
"title": "Order Item Count"
106-
}
77+
"item_count": {
78+
"type": "integer",
79+
"exclusiveMinimum": 0.0,
80+
"title": "Item Count",
81+
"description": "Amount of items in order"
82+
},
83+
"id": {
84+
"type": "string",
85+
"maxLength": 36,
86+
"minLength": 36,
87+
"title": "Id",
88+
"description": "Order ID as UUID"
89+
}
90+
},
91+
"type": "object",
92+
"required": [
93+
"name",
94+
"item_count",
95+
"id"
96+
],
97+
"title": "CreateOrderOutput"
98+
},
99+
"CreateOrderRequest": {
100+
"properties": {
101+
"customer_name": {
102+
"type": "string",
103+
"maxLength": 20,
104+
"minLength": 1,
105+
"title": "Customer Name",
106+
"description": "Customer name"
107+
},
108+
"order_item_count": {
109+
"type": "integer",
110+
"exclusiveMinimum": 0.0,
111+
"title": "Order Item Count",
112+
"description": "Amount of items in order"
113+
}
114+
},
115+
"type": "object",
116+
"required": [
117+
"customer_name",
118+
"order_item_count"
119+
],
120+
"title": "CreateOrderRequest"
121+
},
122+
"InternalServerErrorOutput": {
123+
"properties": {
124+
"error": {
125+
"type": "string",
126+
"title": "Error",
127+
"description": "Error description",
128+
"default": "internal server error"
129+
}
130+
},
131+
"type": "object",
132+
"title": "InternalServerErrorOutput"
133+
},
134+
"InvalidRestApiRequest": {
135+
"properties": {
136+
"details": {
137+
"items": {
138+
"$ref": "#/components/schemas/PydanticError"
139+
},
140+
"type": "array",
141+
"title": "Details",
142+
"description": "Error details"
143+
}
144+
},
145+
"type": "object",
146+
"required": [
147+
"details"
148+
],
149+
"title": "InvalidRestApiRequest"
150+
},
151+
"PydanticError": {
152+
"properties": {
153+
"loc": {
154+
"items": {
155+
"anyOf": [
156+
{
157+
"type": "string"
158+
},
159+
{
160+
"type": "integer"
161+
}
162+
]
163+
},
164+
"type": "array",
165+
"title": "Loc",
166+
"description": "Error location"
167+
},
168+
"type": {
169+
"type": "string",
170+
"title": "Type",
171+
"description": "Error type"
172+
},
173+
"msg": {
174+
"anyOf": [
175+
{
176+
"type": "string"
107177
},
108-
"type": "object",
109-
"required": [
110-
"customer_name",
111-
"order_item_count"
112-
],
113-
"title": "CreateOrderRequest"
178+
{
179+
"type": "null"
180+
}
181+
],
182+
"title": "Msg",
183+
"description": "Error message"
114184
}
185+
},
186+
"type": "object",
187+
"required": [
188+
"loc",
189+
"type",
190+
"msg"
191+
],
192+
"title": "PydanticError"
115193
}
194+
}
116195
}
117-
}
196+
}

package-lock.json

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

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
{
22
"dependencies": {
3-
"aws-cdk": "2.121.1"
3+
"aws-cdk": "2.122.0"
44
}
55
}

0 commit comments

Comments
 (0)