Skip to content

Commit

Permalink
fix(dynamodb-global): cannot deploy global tables due to unresolved r…
Browse files Browse the repository at this point in the history
…esource dependencies

The DynamoDB global table construct was incorrectly declaring its dependencies,
having the coordinator stack depend on the resources in the table stacks,
instead of on the stacks themselves.
That resulted in resources in the coordinator stack depending on the global tables,
which cannot work, as those are from different stacks.
Changed the logic to declare dependencies between the stacks explicitly.

Fixes #4676
  • Loading branch information
skinny85 authored Nov 5, 2019
1 parent 47124bf commit 45f0e02
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -51,17 +51,17 @@ export class GlobalTable extends cdk.Construct {
stream: dynamodb.StreamViewType.NEW_AND_OLD_IMAGES,
};

this.lambdaGlobalTableCoordinator = new GlobalTableCoordinator(scope, id + "-CustomResource", props);

// here we loop through the configured regions.
// in each region we'll deploy a separate stack with a DynamoDB Table with identical properties in the individual stacks
for (const reg of props.regions) {
const regionalStack = new cdk.Stack(this, id + "-" + reg, { env: { region: reg } });
const regionalTable = new dynamodb.Table(regionalStack, `${id}-GlobalTable-${reg}`, regionalTableProps);
this._regionalTables.push(regionalTable);
}

this.lambdaGlobalTableCoordinator = new GlobalTableCoordinator(scope, id + "-CustomResource", props);
for (const table of this._regionalTables) {
this.lambdaGlobalTableCoordinator.node.addDependency(table);
// deploy the regional stack before the Lambda coordinator stack
this.lambdaGlobalTableCoordinator.addDependency(regionalStack);
}
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
[
{
},
{
"Resources": {
"globdynamodbintegGlobalTableuseast162596384": {
Expand Down Expand Up @@ -248,4 +250,4 @@
}
}
}
]
]
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
/// !cdk-integ *
import { AttributeType } from '@aws-cdk/aws-dynamodb';
import { App, RemovalPolicy } from '@aws-cdk/core';
import { App, RemovalPolicy, Stack } from '@aws-cdk/core';
import { GlobalTable } from '../lib';

const app = new App();
new GlobalTable(app, 'globdynamodbinteg', {
const stack = new Stack(app, 'Default');
new GlobalTable(stack, 'globdynamodbinteg', {
partitionKey: { name: 'hashKey', type: AttributeType.STRING },
tableName: 'integrationtest',
regions: ["us-east-1", "us-east-2", "us-west-2"],
Expand Down

0 comments on commit 45f0e02

Please sign in to comment.