Skip to content

Commit b31786d

Browse files
heitorlessarubenfonseca
authored andcommitted
refactor(e2e): make table name dynamic
1 parent 79a676f commit b31786d

File tree

4 files changed

+21
-14
lines changed

4 files changed

+21
-14
lines changed

tests/e2e/idempotency/handlers/parallel_execution_handler.py

+3-1
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,10 @@
1+
import os
12
import time
23

34
from aws_lambda_powertools.utilities.idempotency import DynamoDBPersistenceLayer, idempotent
45

5-
persistence_layer = DynamoDBPersistenceLayer(table_name="IdempotencyTable")
6+
TABLE_NAME = os.getenv("IdempotencyTable", "")
7+
persistence_layer = DynamoDBPersistenceLayer(table_name=TABLE_NAME)
68

79

810
@idempotent(persistence_store=persistence_layer)

tests/e2e/idempotency/handlers/ttl_cache_expiration_handler.py

+3-1
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,10 @@
1+
import os
12
import time
23

34
from aws_lambda_powertools.utilities.idempotency import DynamoDBPersistenceLayer, IdempotencyConfig, idempotent
45

5-
persistence_layer = DynamoDBPersistenceLayer(table_name="IdempotencyTable")
6+
TABLE_NAME = os.getenv("IdempotencyTable", "")
7+
persistence_layer = DynamoDBPersistenceLayer(table_name=TABLE_NAME)
68
config = IdempotencyConfig(expires_after_seconds=20)
79

810

tests/e2e/idempotency/handlers/ttl_cache_timeout_handler.py

+3-1
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,10 @@
1+
import os
12
import time
23

34
from aws_lambda_powertools.utilities.idempotency import DynamoDBPersistenceLayer, IdempotencyConfig, idempotent
45

5-
persistence_layer = DynamoDBPersistenceLayer(table_name="IdempotencyTable")
6+
TABLE_NAME = os.getenv("IdempotencyTable", "")
7+
persistence_layer = DynamoDBPersistenceLayer(table_name=TABLE_NAME)
68
config = IdempotencyConfig(expires_after_seconds=1)
79

810

+12-11
Original file line numberDiff line numberDiff line change
@@ -1,30 +1,31 @@
1-
from typing import Dict
2-
31
from aws_cdk import CfnOutput, RemovalPolicy
42
from aws_cdk import aws_dynamodb as dynamodb
5-
from aws_cdk.aws_lambda import Function
3+
from aws_cdk.aws_dynamodb import Table
64

75
from tests.e2e.utils.infrastructure import BaseInfrastructure
86

97

108
class IdempotencyDynamoDBStack(BaseInfrastructure):
119
def create_resources(self):
12-
functions = self.create_lambda_functions()
13-
self._create_dynamodb_table(functions=functions)
10+
table = self._create_dynamodb_table()
11+
12+
env_vars = {"IdempotencyTable": table.table_name}
13+
functions = self.create_lambda_functions(function_props={"environment": env_vars})
14+
15+
table.grant_read_write_data(functions["TtlCacheExpirationHandler"])
16+
table.grant_read_write_data(functions["TtlCacheTimeoutHandler"])
17+
table.grant_read_write_data(functions["ParallelExecutionHandler"])
1418

15-
def _create_dynamodb_table(self, functions: Dict[str, Function]):
19+
def _create_dynamodb_table(self) -> Table:
1620
table = dynamodb.Table(
1721
self.stack,
1822
"Idempotency",
19-
table_name="IdempotencyTable",
2023
removal_policy=RemovalPolicy.DESTROY,
2124
partition_key=dynamodb.Attribute(name="id", type=dynamodb.AttributeType.STRING),
2225
time_to_live_attribute="expiration",
2326
billing_mode=dynamodb.BillingMode.PAY_PER_REQUEST,
2427
)
2528

26-
table.grant_read_write_data(functions["TtlCacheExpirationHandler"])
27-
table.grant_read_write_data(functions["TtlCacheTimeoutHandler"])
28-
table.grant_read_write_data(functions["ParallelExecutionHandler"])
29-
3029
CfnOutput(self.stack, "DynamoDBTable", value=table.table_name)
30+
31+
return table

0 commit comments

Comments
 (0)