From e1662cecd272feb67bb8f411be5da5493291d413 Mon Sep 17 00:00:00 2001 From: Jonathan Goldwasser Date: Fri, 19 Feb 2021 10:18:11 +0100 Subject: [PATCH] fix(dynamodb): replicas not created on table replacement Closes #12332 --- .../aws-dynamodb/lib/replica-handler/index.ts | 33 +++++++-- packages/@aws-cdk/aws-dynamodb/lib/table.ts | 13 +++- .../test/integ.global.expected.json | 68 ++++++++++++------- 3 files changed, 81 insertions(+), 33 deletions(-) diff --git a/packages/@aws-cdk/aws-dynamodb/lib/replica-handler/index.ts b/packages/@aws-cdk/aws-dynamodb/lib/replica-handler/index.ts index 814bad346ece2..2c800804cb919 100644 --- a/packages/@aws-cdk/aws-dynamodb/lib/replica-handler/index.ts +++ b/packages/@aws-cdk/aws-dynamodb/lib/replica-handler/index.ts @@ -5,18 +5,16 @@ import { DynamoDB } from 'aws-sdk'; // eslint-disable-line import/no-extraneous- export async function onEventHandler(event: OnEventRequest): Promise { console.log('Event: %j', event); - /** - * Process only Create and Delete requests. We shouldn't receive any - * update request and in case we do there is nothing to update. - */ - if (event.RequestType === 'Create' || event.RequestType === 'Delete') { + const updateTableAction = getUpdateTableAction(event); + + if (updateTableAction) { const dynamodb = new DynamoDB(); const data = await dynamodb.updateTable({ TableName: event.ResourceProperties.TableName, ReplicaUpdates: [ { - [event.RequestType]: { + [updateTableAction]: { RegionName: event.ResourceProperties.Region, }, }, @@ -25,7 +23,7 @@ export async function onEventHandler(event: OnEventRequest): Promise { @@ -53,3 +51,24 @@ export async function isCompleteHandler(event: IsCompleteRequest): Promise