Skip to content

Commit c326388

Browse files
chore(dynamodb): changing language for multi-attribute keys on GSI's (#36233)
### Issue # (if applicable) No issue raised ### Reason for this change Language around multi-attribute keys for global secondary indexes needed updating. ### Description of changes Descriptions of attributes changed, no code changes. ### Describe any new or updated permissions being added ### Description of how you validated changes ### Checklist - [X] My code adheres to the [CONTRIBUTING GUIDE](https://github.com/aws/aws-cdk/blob/main/CONTRIBUTING.md) and [DESIGN GUIDELINES](https://github.com/aws/aws-cdk/blob/main/docs/DESIGN_GUIDELINES.md) ---- *By submitting this pull request, I confirm that my contribution is made under the terms of the Apache-2.0 license*
1 parent 599a1d3 commit c326388

File tree

7 files changed

+40
-40
lines changed

7 files changed

+40
-40
lines changed

packages/aws-cdk-lib/aws-dynamodb/README.md

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -404,9 +404,9 @@ const table = new dynamodb.TableV2(this, 'Table', {
404404
});
405405
```
406406

407-
#### Compound Keys
407+
#### Multi-attribute Keys
408408

409-
Global secondary indexes support compound keys, allowing you to specify multiple partition keys and/or multiple sort keys. This enables more flexible query patterns for complex data models.
409+
Global secondary indexes support multi-attribute keys, allowing you to specify multiple partition keys and/or multiple sort keys. This enables more flexible query patterns for complex data models.
410410

411411
**Key Constraints:**
412412
- You can specify up to **4 partition keys** per global secondary index
@@ -417,14 +417,14 @@ Global secondary indexes support compound keys, allowing you to specify multiple
417417
- For multiple keys, you **must** use the plural parameters (`partitionKeys` and/or `sortKeys`)
418418
- **Keys cannot be added or modified after index creation** - attempting to add additional keys to an existing index will result in an error
419419

420-
**Example with compound partition and sort keys:**
420+
**Example with multi-attribute partition and sort keys:**
421421

422422
```ts
423423
const table = new dynamodb.TableV2(this, 'Table', {
424424
partitionKey: { name: 'pk', type: dynamodb.AttributeType.STRING },
425425
globalSecondaryIndexes: [
426426
{
427-
indexName: 'compound-gsi',
427+
indexName: 'multi-attribute-gsi',
428428
partitionKeys: [
429429
{ name: 'gsi_pk1', type: dynamodb.AttributeType.STRING },
430430
{ name: 'gsi_pk2', type: dynamodb.AttributeType.NUMBER },
@@ -456,12 +456,12 @@ table.addGlobalSecondaryIndex({
456456
partitionKey: { name: 'pk', type: dynamodb.AttributeType.STRING },
457457
});
458458

459-
// Add a GSI with compound keys
459+
// Add a GSI with multi-attribute keys
460460
table.addGlobalSecondaryIndex({
461-
indexName: 'compound-gsi2',
461+
indexName: 'multi-attribute-gsi2',
462462
partitionKeys: [
463-
{ name: 'compound_pk1', type: dynamodb.AttributeType.STRING },
464-
{ name: 'compound_pk2', type: dynamodb.AttributeType.NUMBER },
463+
{ name: 'multi-attribute_pk1', type: dynamodb.AttributeType.STRING },
464+
{ name: 'multi-attribute_pk2', type: dynamodb.AttributeType.NUMBER },
465465
],
466466
sortKey: { name: 'sk', type: dynamodb.AttributeType.STRING },
467467
});

packages/aws-cdk-lib/aws-dynamodb/TABLE_V1_API.md

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -211,12 +211,12 @@ To get the partition key and sort key of the table or indexes you have configure
211211
```ts
212212
declare const table: dynamodb.Table;
213213

214-
// For single keys, use schema() (deprecated for compound keys)
214+
// For single keys, use schema() (deprecated for multi-attribute keys)
215215
const schema = table.schema();
216216
const partitionKey = schema.partitionKey;
217217
const sortKey = schema.sortKey;
218218

219-
// For compound keys, use schemaV2() which returns normalized arrays
219+
// For multi-attribute keys, use schemaV2() which returns normalized arrays
220220
const schemaV2 = table.schemaV2();
221221
const partitionKeys = schemaV2.partitionKeys; // Attribute[]
222222
const sortKeys = schemaV2.sortKeys; // Attribute[]
@@ -225,11 +225,11 @@ const sortKeys = schemaV2.sortKeys; // Attribute[]
225225
const indexSchema = table.schemaV2('INDEX_NAME');
226226
```
227227

228-
Note: `schema()` is deprecated for indexes with compound keys and will throw an error. Use `schemaV2()` instead, which always returns normalized arrays.
228+
Note: `schema()` is deprecated for indexes with multi-attribute keys and will throw an error. Use `schemaV2()` instead, which always returns normalized arrays.
229229

230-
## Global Secondary Indexes with Compound Keys
230+
## Global Secondary Indexes with multi-attribute Keys
231231

232-
Global secondary indexes support compound keys, allowing you to specify multiple partition keys and/or multiple sort keys. This enables more flexible query patterns for complex data models.
232+
Global secondary indexes support multi-attribute keys, allowing you to specify multiple partition keys and/or multiple sort keys. This enables more flexible query patterns for complex data models.
233233

234234
**Key Constraints:**
235235
- You can specify up to **4 partition keys** per global secondary index
@@ -249,7 +249,7 @@ const table = new dynamodb.Table(this, 'Table', {
249249
});
250250

251251
table.addGlobalSecondaryIndex({
252-
indexName: 'compound-gsi',
252+
indexName: 'multi-attribute-gsi',
253253
partitionKeys: [
254254
{ name: 'gsi_pk1', type: dynamodb.AttributeType.STRING },
255255
{ name: 'gsi_pk2', type: dynamodb.AttributeType.NUMBER },

packages/aws-cdk-lib/aws-dynamodb/lib/shared.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -565,15 +565,15 @@ export interface KeySchema {
565565
}
566566

567567
/**
568-
* A key schema that combines the legacy properties (singular keys) with the modern properties (compound keys)
568+
* A key schema that combines the legacy properties (singular keys) with the modern properties (multi-attribute keys)
569569
*
570570
* Picking from an existing type is an easy way to get these without having to copy/paste them all, but we could
571571
* have also done the copy/pasting. This type is never exported.
572572
*/
573573
type CompatibleKeySchema = Pick<GlobalSecondaryIndexProps, 'partitionKey' | 'partitionKeys' | 'sortKey' | 'sortKeys'>;
574574

575575
/**
576-
* Parse a backwards compatible key schema to a strictly compound key schema, and validate the contents
576+
* Parse a backwards compatible key schema to a strictly multi-attribute key schema, and validate the contents
577577
*/
578578
export function parseKeySchema(schema: CompatibleKeySchema, scope: IConstruct): KeySchema {
579579
if ((schema.partitionKey === undefined) === (schema.partitionKeys === undefined)) {

packages/aws-cdk-lib/aws-dynamodb/lib/table-v2.ts

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,7 @@ export interface GlobalSecondaryIndexPropsV2 extends SecondaryIndexProps {
9494
* Partition key attribute definition.
9595
*
9696
* If a single field forms the partition key, you can use this field. Use the
97-
* `partitionKeys` field if the partition key is a compound key (consists of
97+
* `partitionKeys` field if the partition key is a multi-attribute key (consists of
9898
* multiple fields).
9999
*
100100
* @default - exactly one of `partitionKey` and `partitionKeys` must be specified.
@@ -105,21 +105,21 @@ export interface GlobalSecondaryIndexPropsV2 extends SecondaryIndexProps {
105105
* Sort key attribute definition.
106106
*
107107
* If a single field forms the sort key, you can use this field. Use the
108-
* `sortKeys` field if the sort key is a compound key (consists of multiple
108+
* `sortKeys` field if the sort key is a multi-attribute key (consists of multiple
109109
* fields).
110110
*
111111
* @default - no sort key
112112
*/
113113
readonly sortKey?: Attribute;
114114

115115
/**
116-
* Compound partition key
116+
* Multi-attribute partition key
117117
*
118118
* If a single field forms the partition key, you can use either
119119
* `partitionKey` or `partitionKeys` to specify the partition key. Exactly
120120
* one of these must be specified.
121121
*
122-
* You must use `partitionKeys` field if the partition key is a compound key
122+
* You must use `partitionKeys` field if the partition key is a multi-attribute key
123123
* (consists of multiple fields).
124124
*
125125
* NOTE: although the name of this field makes it sound like it creates
@@ -133,13 +133,13 @@ export interface GlobalSecondaryIndexPropsV2 extends SecondaryIndexProps {
133133
readonly partitionKeys?: Attribute[];
134134

135135
/**
136-
* Compound sort key
136+
* Multi-attribute sort key
137137
*
138138
* If a single field forms the sort key, you can use either
139139
* `sortKey` or `sortKeys` to specify the sort key. At most one of these
140140
* may be specified.
141141
*
142-
* You must use `sortKeys` field if the sort key is a compound key
142+
* You must use `sortKeys` field if the sort key is a multi-attribute key
143143
* (consists of multiple fields).
144144
*
145145
* NOTE: although the name of this field makes it sound like it creates

packages/aws-cdk-lib/aws-dynamodb/lib/table.ts

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ export interface SchemaOptions {
4848
* Partition key attribute definition.
4949
*
5050
* If a single field forms the partition key, you can use this field. Use the
51-
* `partitionKeys` field if the partition key is a compound key (consists of
51+
* `partitionKeys` field if the partition key is a multi-attribute key (consists of
5252
* multiple fields).
5353
*
5454
* @default - exactly one of `partitionKey` and `partitionKeys` must be specified.
@@ -59,7 +59,7 @@ export interface SchemaOptions {
5959
* Sort key attribute definition.
6060
*
6161
* If a single field forms the sort key, you can use this field. Use the
62-
* `sortKeys` field if the sort key is a compound key (consists of multiple
62+
* `sortKeys` field if the sort key is a multi-attribute key (consists of multiple
6363
* fields).
6464
*
6565
* @default - no sort key
@@ -515,13 +515,13 @@ export interface TableProps extends TableOptions {
515515
*/
516516
export interface GlobalSecondaryIndexProps extends SecondaryIndexProps, SchemaOptions {
517517
/**
518-
* Compound partition key
518+
* Multi-attribute partition key
519519
*
520520
* If a single field forms the partition key, you can use either
521521
* `partitionKey` or `partitionKeys` to specify the partition key. Exactly
522522
* one of these must be specified.
523523
*
524-
* You must use `partitionKeys` field if the partition key is a compound key
524+
* You must use `partitionKeys` field if the partition key is a multi-attribute key
525525
* (consists of multiple fields).
526526
*
527527
* NOTE: although the name of this field makes it sound like it creates
@@ -535,13 +535,13 @@ export interface GlobalSecondaryIndexProps extends SecondaryIndexProps, SchemaOp
535535
readonly partitionKeys?: Attribute[];
536536

537537
/**
538-
* Compound sort key
538+
* Multi-attribute sort key
539539
*
540540
* If a single field forms the sort key, you can use either
541541
* `sortKey` or `sortKeys` to specify the sort key. At most one of these
542542
* may be specified.
543543
*
544-
* You must use `sortKeys` field if the sort key is a compound key
544+
* You must use `sortKeys` field if the sort key is a multi-attribute key
545545
* (consists of multiple fields).
546546
*
547547
* NOTE: although the name of this field makes it sound like it creates
@@ -1580,7 +1580,7 @@ export class Table extends TableBase {
15801580
}
15811581

15821582
if (schema.partitionKeys.length > 1 || schema.sortKeys.length > 1) {
1583-
throw new ValidationError(`Index ${indexName} uses compound keys and cannot be returned by schema(), use schemaV2() instead.`, this);
1583+
throw new ValidationError(`Index ${indexName} uses multi-attribute keys and cannot be returned by schema(), use schemaV2() instead.`, this);
15841584
}
15851585

15861586
return {

packages/aws-cdk-lib/aws-dynamodb/test/dynamodb.test.ts

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1358,7 +1358,7 @@ describe('schema details', () => {
13581358
});
13591359
});
13601360

1361-
test('get normalized schema for GSI with compound partition keys', () => {
1361+
test('get normalized schema for GSI with multi-attribute partition keys', () => {
13621362
const pk1: Attribute = { name: 'pk1', type: AttributeType.STRING };
13631363
const pk2: Attribute = { name: 'pk2', type: AttributeType.STRING };
13641364

@@ -1373,7 +1373,7 @@ describe('schema details', () => {
13731373
});
13741374
});
13751375

1376-
test('get normalized schema for GSI with compound sort keys', () => {
1376+
test('get normalized schema for GSI with multi-attribute sort keys', () => {
13771377
const sk1: Attribute = { name: 'sk1', type: AttributeType.STRING };
13781378
const sk2: Attribute = { name: 'sk2', type: AttributeType.STRING };
13791379

@@ -4879,7 +4879,7 @@ test('ContributorInsightsSpecification && ContributorInsightsEnabled', () => {
48794879
}).toThrow('`contributorInsightsSpecification` and `contributorInsightsEnabled` are set. Use `contributorInsightsSpecification` only.');
48804880
});
48814881

4882-
test('Compound partition keys for global secondary index', () => {
4882+
test('Multi-attribute partition keys for global secondary index', () => {
48834883
const stack = new Stack();
48844884

48854885
const table = new Table(stack, CONSTRUCT_NAME, {
@@ -4918,7 +4918,7 @@ test('Compound partition keys for global secondary index', () => {
49184918
);
49194919
});
49204920

4921-
test('Compound partition keys and standard sort key for global secondary index', () => {
4921+
test('Multi-attribute partition keys and standard sort key for global secondary index', () => {
49224922
const stack = new Stack();
49234923

49244924
const table = new Table(stack, CONSTRUCT_NAME, {
@@ -4960,7 +4960,7 @@ test('Compound partition keys and standard sort key for global secondary index',
49604960
);
49614961
});
49624962

4963-
test('Throws when compound partitionKeys and partitionKey are specified', () => {
4963+
test('Throws when multi-attribute partitionKeys and partitionKey are specified', () => {
49644964
const stack = new Stack();
49654965
expect(() => {
49664966
const table = new Table(stack, CONSTRUCT_NAME, {
@@ -4977,7 +4977,7 @@ test('Throws when compound partitionKeys and partitionKey are specified', () =>
49774977
}).toThrow('Exactly one of \'partitionKey\', \'partitionKeys\' must be specified');
49784978
});
49794979

4980-
test('Throws when compound sortKeys and sortKey are specified', () => {
4980+
test('Throws when multi-attribute sortKeys and sortKey are specified', () => {
49814981
const stack = new Stack();
49824982
expect(() => {
49834983
const table = new Table(stack, CONSTRUCT_NAME, {
@@ -4994,7 +4994,7 @@ test('Throws when compound sortKeys and sortKey are specified', () => {
49944994
}).toThrow('At most one of \'sortKey\', \'sortKeys\' may be specified');
49954995
});
49964996

4997-
test('Throws when more than four compound partition keys are specified', () => {
4997+
test('Throws when more than four multi-attribute partition keys are specified', () => {
49984998
const stack = new Stack();
49994999
expect(() => {
50005000
const table = new Table(stack, CONSTRUCT_NAME, {
@@ -5013,7 +5013,7 @@ test('Throws when more than four compound partition keys are specified', () => {
50135013
}).toThrow('Maximum of 4 partition keys allowed');
50145014
});
50155015

5016-
test('Throws when more than four compound sort keys are specified', () => {
5016+
test('Throws when more than four multi-attribute sort keys are specified', () => {
50175017
const stack = new Stack();
50185018
expect(() => {
50195019
const table = new Table(stack, CONSTRUCT_NAME, {

packages/aws-cdk-lib/aws-dynamodb/test/table-v2.test.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3716,7 +3716,7 @@ test('ContributorInsightsSpecification && ContributorInsights - v2', () => {
37163716
}).toThrow('`contributorInsightsSpecification` and `contributorInsights` are set. Use `contributorInsightsSpecification` only.');
37173717
});
37183718

3719-
test('can add GSI with compound partition keys', () => {
3719+
test('can add GSI with multi-attribute partition keys', () => {
37203720
const stack = new Stack();
37213721
const table = new TableV2(stack, 'Table', {
37223722
partitionKey: { name: 'pk', type: AttributeType.STRING },
@@ -3748,7 +3748,7 @@ test('can add GSI with compound partition keys', () => {
37483748
});
37493749
});
37503750

3751-
test('can add GSI with compound sort keys', () => {
3751+
test('can add GSI with multi-attribute sort keys', () => {
37523752
const stack = new Stack();
37533753
const table = new TableV2(stack, 'Table', {
37543754
partitionKey: { name: 'pk', type: AttributeType.STRING },
@@ -3862,7 +3862,7 @@ test('throws when no partition key specified', () => {
38623862
}).toThrow('Exactly one of \'partitionKey\', \'partitionKeys\' must be specified');
38633863
});
38643864

3865-
test('can add GSI with both compound partition and sort keys', () => {
3865+
test('can add GSI with both multi-attribute partition and sort keys', () => {
38663866
const stack = new Stack();
38673867
const table = new TableV2(stack, 'Table', {
38683868
partitionKey: { name: 'pk', type: AttributeType.STRING },

0 commit comments

Comments
 (0)