DynamoDBConfig¶
Bases: BaseModel, NameValidationMixin
Configuration model for DynamoDB table creation and management.
Comprehensive configuration model that defines all aspects of a DynamoDB table including key schema, indexes, streaming, and metadata. This model validates the complete table structure and ensures consistency between primary keys and secondary indexes.
Attributes:
| Name | Type | Description |
|---|---|---|
enable_stream |
bool
|
Enable DynamoDB Streams for change data capture |
pk |
PartitionKey
|
Primary partition key configuration for item distribution |
sk |
Optional[SortKey]
|
Optional sort key for composite primary keys and range queries |
indexes |
Optional[Dict[str, GlobalSecondaryIndex]]
|
Global Secondary Index configurations for alternative access patterns |
tag_key |
str
|
Primary tag key for backup and operational policies |
tag_value |
str
|
Primary tag value for backup and operational policies |
table_base_name |
str
|
Base identifier for the table following naming conventions |
Source code in mare_aws_common_lib/models/dynamodb_config.py
85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 | |
validate_table_name(value)
classmethod
¶
Validate the DynamoDB table base name.
Applies validation rules to table naming to ensure the name meets AWS requirements and organizational standards.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
value
|
str
|
Raw table base name from configuration |
required |
Returns:
| Type | Description |
|---|---|
str
|
Validated table base name |
Raises:
| Type | Description |
|---|---|
ValueError
|
If the table name fails validation rules |
Source code in mare_aws_common_lib/models/dynamodb_config.py
116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 | |
Example
from mare_aws_common_lib.models import DynamoDBConfig
config = DynamoDBConfig(
table_base_name="users-sessions",
pk=PartitionKey(name="user_id", type=AttributeType.STRING),
sk=SortKey(name="session_id", type=AttributeType.STRING),
enable_stream=True,
indexes={
"status-index": GlobalSecondaryIndex(
pk=PartitionKey(name="status", type=AttributeType.STRING),
sk=SortKey(name="expires_at", type=AttributeType.NUMBER)
)
},
tag_key="Environment",
tag_value="Production"
)
AttributeType
¶
Bases: str, Enum
DynamoDB attribute data types with CDK conversion support.
Represents the three fundamental attribute types supported by DynamoDB and provides conversion to CDK AttributeType constants for seamless integration with AWS CDK DynamoDB constructs.
Attributes:
| Name | Type | Description |
|---|---|---|
STRING |
Text-based data type for strings and Unicode characters |
|
NUMBER |
Numeric data type for integers and floating-point numbers |
|
BINARY |
Binary data type for binary data, images, and compressed objects |
Source code in mare_aws_common_lib/models/dynamodb_config.py
7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 | |
as_cdk
property
¶
CDK-compatible representation of the DynamoDB attribute type.
Returns:
| Type | Description |
|---|---|
AttributeType
|
CDK DynamoDB AttributeType constant matching this enum value |
GlobalSecondaryIndex
¶
Bases: BaseModel
Configuration model for DynamoDB Global Secondary Indexes (GSI).
Defines the structure of a Global Secondary Index, which provides alternative query patterns on a DynamoDB table. GSIs have their own partition key and optional sort key, independent of the base table.
Attributes:
| Name | Type | Description |
|---|---|---|
pk |
PartitionKey
|
Partition key configuration for the index |
sk |
Optional[SortKey]
|
Optional sort key configuration for the index |
Note
GSIs enable querying on different attributes than the main table's primary key, providing flexible access patterns for applications.
Source code in mare_aws_common_lib/models/dynamodb_config.py
66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 | |
Example
from mare_aws_common_lib.models import GlobalSecondaryIndex, AttributeType, PartitionKey, SortKey
gsi = GlobalSecondaryIndex(
pk=PartitionKey(name="status", type=AttributeType.STRING),
sk=SortKey(name="created_at", type=AttributeType.NUMBER)
)
PartitionKey
¶
Bases: BaseModel
Configuration model for DynamoDB table partition keys.
Defines the partition key (primary key) structure for a DynamoDB table. The partition key determines how data is distributed across multiple partitions and is required for all DynamoDB tables.
Attributes:
| Name | Type | Description |
|---|---|---|
name |
str
|
Attribute name for the partition key (defaults to 'pk') |
type |
AttributeType
|
Data type of the partition key attribute |
Source code in mare_aws_common_lib/models/dynamodb_config.py
36 37 38 39 40 41 42 43 44 45 46 47 48 49 | |
Example
from mare_aws_common_lib.models import PartitionKey, AttributeType
pk = PartitionKey(name="user_id", type=AttributeType.STRING)
SortKey
¶
Bases: BaseModel
Configuration model for DynamoDB table sort keys.
Defines the sort key (range key) structure for a DynamoDB table. Sort keys are optional and enable querying items with the same partition key in sorted order, creating composite primary keys.
Attributes:
| Name | Type | Description |
|---|---|---|
name |
str
|
Attribute name for the sort key (defaults to 'sk') |
type |
AttributeType
|
Data type of the sort key attribute |
Source code in mare_aws_common_lib/models/dynamodb_config.py
51 52 53 54 55 56 57 58 59 60 61 62 63 64 | |
Example
from mare_aws_common_lib.models import SortKey, AttributeType
sk = SortKey(name="timestamp", type=AttributeType.NUMBER)