Skip to content

Commit

Permalink
Merge pull request #778 from PRX/feat/ddb_global_sort_key
Browse files Browse the repository at this point in the history
Add optional sort key as part of primary key
  • Loading branch information
kookster authored Sep 19, 2024
2 parents 716d590 + 20adffc commit 5b0cd97
Showing 1 changed file with 30 additions and 3 deletions.
33 changes: 30 additions & 3 deletions db/dynamodb-global-table.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
AWSTemplateFormatVersion: "2010-09-09"

Description: >-
Create a global primary-key-lookup DynamoDB table
Create a global primary-key-lookup DynamoDB table with an optional sort key
Metadata:
AWS::CloudFormation::Interface:
Expand All @@ -13,6 +13,8 @@ Metadata:
- TableName
- PrimaryKey
- PrimaryType
- SortKey
- SortType
- ExpirationField
- Label:
default: Optional Regions
Expand Down Expand Up @@ -47,9 +49,13 @@ Metadata:
TableName:
default: Table name
PrimaryKey:
default: Primary key field
default: Partition key field
PrimaryType:
default: Primary key type
default: Partition key type
SortKey:
default: Sort key field
SortType:
default: Sort key type
ExpirationField:
default: Field to enable expiration on
Region2:
Expand Down Expand Up @@ -101,6 +107,16 @@ Parameters:
- String
- Numeric
- Binary
SortKey:
Type: String
Description: The name of the sort key field (optional)
SortType:
Type: String
Description: The type of the sort key field
AllowedValues:
- String
- Numeric
- Binary
ExpirationField:
Type: String
Description: Optionally enable Time-To-Live on this field
Expand Down Expand Up @@ -179,6 +195,7 @@ Conditions:
HasForeignAccount: !Not [!Equals [!Ref ForeignAccountId, ""]]
HasForeignRole: !Not [!Equals [!Ref ForeignRoleName, ""]]
HasProvisionedBilling: !Equals [!Ref BillingMode, "PROVISIONED"]
HasSortKey: !Not [!Equals [!Ref SortKey, ""]]

Mappings:
DataTypesMap:
Expand All @@ -196,10 +213,20 @@ Resources:
AttributeDefinitions:
- AttributeName: !Ref PrimaryKey
AttributeType: !FindInMap [DataTypesMap, !Ref PrimaryType, Symbol]
- Fn::If:
- HasSortKey
- AttributeName: !Ref SortKey
AttributeType: !FindInMap [DataTypesMap, !Ref SortType, Symbol]
- !Ref AWS::NoValue
BillingMode: !Ref BillingMode
KeySchema:
- AttributeName: !Ref PrimaryKey
KeyType: HASH
- Fn::If:
- HasSortKey
- AttributeName: !Ref SortKey
KeyType: RANGE
- !Ref AWS::NoValue
Replicas:
- ReadProvisionedThroughputSettings: !If
- HasProvisionedBilling
Expand Down

0 comments on commit 5b0cd97

Please sign in to comment.