Skip to content

Commit f5cb4f5

Browse files
ran-isenbergRan Isenberg
andauthored
feature: add support for dynamo v2 (#798)
* feature: add support for dynamo v2 poetry update --------- Co-authored-by: Ran Isenberg <ran.isenberg@ranthebuilder.cloud>
1 parent 69e5fda commit f5cb4f5

File tree

13 files changed

+150
-139
lines changed

13 files changed

+150
-139
lines changed

.github/workflows/main-serverless-service.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ jobs:
7171
env:
7272
ENVIRONMENT: staging # Custom environment variable
7373
- name: Codecov
74-
uses: codecov/codecov-action@eaaf4bedf32dbdc6b720b63067d99c4d77d6047d # v3.1.4
74+
uses: codecov/codecov-action@f30e4959ba63075080d4f7f90cacc18d9f3fafd7 # v4.0.0
7575
with:
7676
token: ${{ secrets.CODECOV_TOKEN }}
7777
files: ./coverage.xml

.github/workflows/pr-serverless-service.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,7 @@ jobs:
9292
- name: Code coverage tests
9393
run: make coverage-tests
9494
- name: Codecov
95-
uses: codecov/codecov-action@eaaf4bedf32dbdc6b720b63067d99c4d77d6047d # v3.1.4
95+
uses: codecov/codecov-action@f30e4959ba63075080d4f7f90cacc18d9f3fafd7 # v4.0.0
9696
with:
9797
token: ${{ secrets.CODECOV_TOKEN }}
9898
files: ./coverage.xml

.github/workflows/scorecard.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ jobs:
5959
# Upload the results as artifacts (optional). Commenting out will disable uploads of run results in SARIF
6060
# format to the repository Actions tab.
6161
- name: "Upload artifact"
62-
uses: actions/upload-artifact@c7d193f32edcb7bfad88892161225aeda64e9392 # v4.0.0
62+
uses: actions/upload-artifact@26f96dfa697d77e81fd5907df203aa23a56210a8 # v4.3.0
6363
with:
6464
name: SARIF file
6565
path: results.sarif

.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.15
29+
rev: v0.2.0
3030
hooks:
3131
# Run the Ruff linter.
3232
- id: ruff

cdk/service/api_construct.py

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ def _build_api_gw(self) -> aws_apigateway.RestApi:
5858
CfnOutput(self, id=constants.APIGATEWAY, value=rest_api.url).override_logical_id(constants.APIGATEWAY)
5959
return rest_api
6060

61-
def _build_lambda_role(self, db: dynamodb.Table, idempotency_table: dynamodb.Table) -> iam.Role:
61+
def _build_lambda_role(self, db: dynamodb.TableV2, idempotency_table: dynamodb.TableV2) -> iam.Role:
6262
return iam.Role(
6363
self,
6464
constants.SERVICE_ROLE_ARN,
@@ -107,7 +107,12 @@ def _build_common_layer(self) -> PythonLayerVersion:
107107
)
108108

109109
def _add_post_lambda_integration(
110-
self, api_resource: aws_apigateway.Resource, role: iam.Role, db: dynamodb.Table, appconfig_app_name: str, idempotency_table: dynamodb.Table
110+
self,
111+
api_resource: aws_apigateway.Resource,
112+
role: iam.Role,
113+
db: dynamodb.TableV2,
114+
appconfig_app_name: str,
115+
idempotency_table: dynamodb.TableV2,
111116
) -> _lambda.Function:
112117
lambda_function = _lambda.Function(
113118
self,

cdk/service/api_db_construct.py

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -9,17 +9,17 @@ class ApiDbConstruct(Construct):
99
def __init__(self, scope: Construct, id_: str) -> None:
1010
super().__init__(scope, id_)
1111

12-
self.db: dynamodb.Table = self._build_db(id_)
13-
self.idempotency_db: dynamodb.Table = self._build_idempotency_table(id_)
12+
self.db: dynamodb.TableV2 = self._build_db(id_)
13+
self.idempotency_db: dynamodb.TableV2 = self._build_idempotency_table(id_)
1414

15-
def _build_idempotency_table(self, id_: str) -> dynamodb.Table:
15+
def _build_idempotency_table(self, id_: str) -> dynamodb.TableV2:
1616
table_id = f'{id_}{constants.IDEMPOTENCY_TABLE_NAME}'
17-
table = dynamodb.Table(
17+
table = dynamodb.TableV2(
1818
self,
1919
table_id,
2020
table_name=table_id,
2121
partition_key=dynamodb.Attribute(name='id', type=dynamodb.AttributeType.STRING),
22-
billing_mode=dynamodb.BillingMode.PAY_PER_REQUEST,
22+
billing=dynamodb.Billing.on_demand(),
2323
removal_policy=RemovalPolicy.DESTROY,
2424
time_to_live_attribute='expiration',
2525
point_in_time_recovery=True,
@@ -29,14 +29,14 @@ def _build_idempotency_table(self, id_: str) -> dynamodb.Table:
2929
)
3030
return table
3131

32-
def _build_db(self, id_prefix: str) -> dynamodb.Table:
32+
def _build_db(self, id_prefix: str) -> dynamodb.TableV2:
3333
table_id = f'{id_prefix}{constants.TABLE_NAME}'
34-
table = dynamodb.Table(
34+
table = dynamodb.TableV2(
3535
self,
3636
table_id,
3737
table_name=table_id,
3838
partition_key=dynamodb.Attribute(name='id', type=dynamodb.AttributeType.STRING),
39-
billing_mode=dynamodb.BillingMode.PAY_PER_REQUEST,
39+
billing=dynamodb.Billing.on_demand(),
4040
point_in_time_recovery=True,
4141
removal_policy=RemovalPolicy.DESTROY,
4242
)

cdk/service/constants.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,8 @@
22
LAMBDA_BASIC_EXECUTION_ROLE = 'AWSLambdaBasicExecutionRole'
33
SERVICE_ROLE = 'ServiceRole'
44
CREATE_LAMBDA = 'CreateOrder'
5-
TABLE_NAME = 'ordersDb'
6-
IDEMPOTENCY_TABLE_NAME = 'IdempotencyTable'
5+
TABLE_NAME = 'orders'
6+
IDEMPOTENCY_TABLE_NAME = 'Idempotency'
77
TABLE_NAME_OUTPUT = 'DbOutput'
88
IDEMPOTENCY_TABLE_NAME_OUTPUT = 'IdempotencyDbOutput'
99
APIGATEWAY = 'Apigateway'

cdk/service/monitoring.py

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,8 @@ def __init__(
2424
scope: Construct,
2525
id_: str,
2626
crud_api: aws_apigateway.RestApi,
27-
db: dynamodb.Table,
28-
idempotency_table: dynamodb.Table,
27+
db: dynamodb.TableV2,
28+
idempotency_table: dynamodb.TableV2,
2929
functions: list[_lambda.Function],
3030
) -> None:
3131
super().__init__(scope, id_)
@@ -84,7 +84,9 @@ def _build_high_level_dashboard(self, crud_api: aws_apigateway.RestApi, topic: s
8484
group = CustomMetricGroup(metrics=[create_metric], title='Daily Order Requests')
8585
high_level_facade.monitor_custom(metric_groups=[group], human_readable_name='Daily KPIs', alarm_friendly_name='KPIs')
8686

87-
def _build_low_level_dashboard(self, db: dynamodb.Table, idempotency_table: dynamodb.Table, functions: list[_lambda.Function], topic: sns.Topic):
87+
def _build_low_level_dashboard(
88+
self, db: dynamodb.TableV2, idempotency_table: dynamodb.TableV2, functions: list[_lambda.Function], topic: sns.Topic
89+
):
8890
low_level_facade = MonitoringFacade(
8991
self,
9092
f'{self.id_}LowFacade',

docs/getting_started.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -77,8 +77,8 @@ If there's an error in the pre-commit stage, it gets auto fixed. However, are re
7777
Be sure to commit all the changes that ``make pr`` does for you.
7878

7979
## **OpenAPI Swagger Generation**
80-
Run either ``make pr`` or ``make openopi`` to generate an updated swagger OpenAPI JSON file and place it at docs/swagger/openapi.json location.
8180

81+
Run either ``make pr`` or ``make openopi`` to generate an updated swagger OpenAPI JSON file and place it at docs/swagger/openapi.json location.
8282

8383
## **GitHub Pages Documentation**
8484

docs/pipeline.md

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,11 @@ The two most important ones are `pr-serverless-service` and `main-serverless-se
5555

5656
It includes two jobs: 'quality_standards' and 'tests' where a failure in 'quality_standards' does not trigger 'tests'. Both jobs MUST pass in order to to be able to merge.
5757

58-
'quality_standards' includes all linters, pre-commit checks and units tests and 'tests' deploys the service to AWS, runs code coverage checks, checks that your OpenAPI file is up to date and corresponds to the actual deployment (fails if it does not, hence your documentation is out of date), security checks and E2E tests. Stack is destroyed at the end. Stack has a 'dev' prefix as part of its name. Each environment has a pre-defined stack prefix.
58+
'quality_standards' includes all linters, pre-commit checks and units tests and 'tests' deploys the service to AWS, runs code coverage checks,
59+
60+
checks that your OpenAPI file is up to date and corresponds to the actual deployment (fails if it does not, hence your documentation is out of date), security checks and E2E tests. Stack is destroyed at the end. Stack has a 'dev'
61+
62+
prefix as part of its name. Each environment has a pre-defined stack prefix.
5963

6064
Once merged, `main-serverless-service` will run.
6165

0 commit comments

Comments
 (0)