Skip to content
This repository was archived by the owner on Jun 19, 2023. It is now read-only.
Closed
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
45 changes: 44 additions & 1 deletion packages/dynamodb-data-mapper/src/DataMapper.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -817,7 +817,8 @@ describe('DataMapper', () => {
ReadCapacityUnits: 5,
WriteCapacityUnits: 5,
},
StreamSpecification: { StreamEnabled: false }
StreamSpecification: { StreamEnabled: false },
SSESpecification: { Enabled: false },
},
]
]);
Expand Down Expand Up @@ -876,6 +877,47 @@ describe('DataMapper', () => {
StreamEnabled: true,
StreamViewType: 'NEW_AND_OLD_IMAGES'
},
SSESpecification: { Enabled: false },
},
]
]);
});

it('should allow enabling sse using kms', async () => {
await mapper.createTable(Item, {
readCapacityUnits: 5,
writeCapacityUnits: 5,
sseSpecification: {
enabled: true,
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 @@ -1068,6 +1110,7 @@ describe('DataMapper', () => {
WriteCapacityUnits: 5,
},
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 @@ -280,6 +280,7 @@ export class DataMapper {
streamViewType = 'NONE',
writeCapacityUnits,
indexOptions = {},
sseSpecification = { enabled: false },
}: CreateTableOptions
) {
const schema = getSchema(valueConstructor.prototype);
Expand All @@ -300,6 +301,13 @@ export class DataMapper {
StreamSpecification: streamViewType === 'NONE'
? { StreamEnabled: false }
: { StreamEnabled: true, StreamViewType: streamViewType },
SSESpecification: sseSpecification.enabled
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is there a use case where someone might change their SSE settings but not enable it? Could this instead check if sseSpecification is defined?

? {
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 @@ -4,8 +4,22 @@ import { PerIndexOptions } from './SecondaryIndexOptions';
export interface CreateTableOptions extends ProvisionedThroughput {
streamViewType?: StreamViewType;
indexOptions?: PerIndexOptions;
sseSpecification?: SseSpecification;
}

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

/**
* 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