Skip to content
This repository was archived by the owner on Jun 19, 2023. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
46 changes: 45 additions & 1 deletion packages/dynamodb-data-mapper/src/DataMapper.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -824,7 +824,8 @@ describe('DataMapper', () => {
ReadCapacityUnits: 5,
WriteCapacityUnits: 5,
},
StreamSpecification: { StreamEnabled: false }
StreamSpecification: { StreamEnabled: false },
SSESpecification: { Enabled: false },
},
]
]);
Expand Down Expand Up @@ -883,6 +884,7 @@ describe('DataMapper', () => {
StreamEnabled: true,
StreamViewType: 'NEW_AND_OLD_IMAGES'
},
SSESpecification: { Enabled: false },
},
]
]);
Expand Down Expand Up @@ -911,6 +913,46 @@ describe('DataMapper', () => {
],
BillingMode: 'PAY_PER_REQUEST',
StreamSpecification: { StreamEnabled: false },
SSESpecification: { Enabled: false },
},
]
]);
});

it('should allow enabling sse using AWS managed CMK', async () => {
await mapper.createTable(Item, {
readCapacityUnits: 5,
writeCapacityUnits: 5,
sseSpecification: {
sseType: 'KMS',
},
});

expect(mockDynamoDbClient.createTable.mock.calls).toEqual([
[
{
TableName: 'foo',
AttributeDefinitions: [
{
AttributeName: 'id',
AttributeType: 'S'
}
],
KeySchema: [
{
AttributeName: 'id',
KeyType: 'HASH',
}
],
ProvisionedThroughput: {
ReadCapacityUnits: 5,
WriteCapacityUnits: 5,
},
StreamSpecification: { StreamEnabled: false },
SSESpecification: {
Enabled: true,
SSEType: 'KMS',
},
},
]
]);
Expand Down Expand Up @@ -1103,6 +1145,7 @@ describe('DataMapper', () => {
WriteCapacityUnits: 5,
},
StreamSpecification: { StreamEnabled: false },
SSESpecification: { Enabled: false },
TableName: 'foo',
},
],
Expand Down Expand Up @@ -1227,6 +1270,7 @@ describe('DataMapper', () => {
],
BillingMode: 'PAY_PER_REQUEST',
StreamSpecification: { StreamEnabled: false },
SSESpecification: { Enabled: false },
TableName: 'foo',
},
],
Expand Down
8 changes: 8 additions & 0 deletions packages/dynamodb-data-mapper/src/DataMapper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -293,6 +293,7 @@ export class DataMapper {
streamViewType = 'NONE',
indexOptions = {},
billingMode,
sseSpecification,
} = options;

const {
Expand All @@ -307,6 +308,13 @@ export class DataMapper {
StreamSpecification: streamViewType === 'NONE'
? { StreamEnabled: false }
: { StreamEnabled: true, StreamViewType: streamViewType },
SSESpecification: sseSpecification
? {
Enabled: true,
SSEType: sseSpecification.sseType,
KMSMasterKeyId: sseSpecification.kmsMasterKeyId,
}
: { Enabled: false },
}).promise();

if (TableStatus !== 'ACTIVE') {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,12 @@ interface BaseCreateTableOptions {
streamViewType?: StreamViewType;
indexOptions?: PerIndexOptions;
billingMode?: BillingMode;
sseSpecification?: SseSpecification;
}

export interface SseSpecification {
sseType: SseType;
kmsMasterKeyId?: string;
}

export interface ProvisionedCreateTableOptions extends ProvisionedThroughput, BaseCreateTableOptions {
Expand All @@ -19,6 +25,13 @@ export type CreateTableOptions = ProvisionedCreateTableOptions | OnDemandCreateT

export type BillingMode = 'PROVISIONED' | 'PAY_PER_REQUEST';

/**
* Server-side encryption type:
* AES256 - Server-side encryption which uses the AES256 algorithm (not applicable).
* KMS - Server-side encryption which uses AWS Key Management Service.
*/
export type SseType = 'AES256' | 'KMS';

export type StreamViewType =
'NEW_IMAGE' |
'OLD_IMAGE' |
Expand Down