|
1 |
| -from typing import Dict |
2 |
| - |
3 | 1 | from aws_cdk import CfnOutput, RemovalPolicy
|
4 | 2 | from aws_cdk import aws_dynamodb as dynamodb
|
5 |
| -from aws_cdk.aws_lambda import Function |
| 3 | +from aws_cdk.aws_dynamodb import Table |
6 | 4 |
|
7 | 5 | from tests.e2e.utils.infrastructure import BaseInfrastructure
|
8 | 6 |
|
9 | 7 |
|
10 | 8 | class IdempotencyDynamoDBStack(BaseInfrastructure):
|
11 | 9 | 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"]) |
14 | 18 |
|
15 |
| - def _create_dynamodb_table(self, functions: Dict[str, Function]): |
| 19 | + def _create_dynamodb_table(self) -> Table: |
16 | 20 | table = dynamodb.Table(
|
17 | 21 | self.stack,
|
18 | 22 | "Idempotency",
|
19 |
| - table_name="IdempotencyTable", |
20 | 23 | removal_policy=RemovalPolicy.DESTROY,
|
21 | 24 | partition_key=dynamodb.Attribute(name="id", type=dynamodb.AttributeType.STRING),
|
22 | 25 | time_to_live_attribute="expiration",
|
23 | 26 | billing_mode=dynamodb.BillingMode.PAY_PER_REQUEST,
|
24 | 27 | )
|
25 | 28 |
|
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 |
| - |
30 | 29 | CfnOutput(self.stack, "DynamoDBTable", value=table.table_name)
|
| 30 | + |
| 31 | + return table |
0 commit comments