Michael Robellard
05/27/2022, 1:35 PMif(scope.region === "us-east-2") {
const replicationRegions = scope.local ? [] : ["ap-southeast-1"]
this.globalchartflowdata = new sst.Table(this, "GlobalChartflowData", {
fields: {
pk: "string",
sk: "string",
gsi1pk: "string",
gsi1sk: "string",
},
primaryIndex: {partitionKey: "pk", sortKey: "sk"},
globalIndexes: {
"GSI1": {partitionKey: "gsi1pk", sortKey: "gsi1sk"},
},
stream: true,
consumers: {
dynamodbstream: {
function: {
srcPath: "backend/",
handler: "services/dynamodbstream/stream.handler",
environment: {
STAGE: props.rootStage,
},
permissions: [new iam.PolicyStatement({
actions: ["ssm:GetParameter", "ssm:GetParameters", "ssm:GetParametersByPath"],
resources: ["*"],
})]
}
}
},
cdk: {
table:
{
replicationRegions: replicationRegions,
}
}
})
}
else{
const tableArn = `arn:aws:dynamodb:${scope.region}:309833148800:table/${props.rootStage}-chartflow-GlobalChartflowData`
this.globalchartflowdata = new sst.Table(this, "GlobalChartflowData", {
cdk: { table: dynamodb.Table.fromTableArn(this, "ImportedTable", tableArn),
}});
this.globalchartflowdata.stream = true;
this.globalchartflowdata.addConsumers(this, {dynamodbstream: {
function: {
srcPath: "backend/",
handler: "services/dynamodbstream/stream.handler",
environment: {
STAGE: props.rootStage,
},
permissions: [new iam.PolicyStatement({
actions: ["ssm:GetParameter", "ssm:GetParameters", "ssm:GetParametersByPath"],
resources: ["*"],
})]
}
}})
}
In the else clause I have tried several variations, including not setting stream = true and trying to set stream = true in the new sst.Table, neither of which work. I either get:
Error: Please enable the "stream" option to add consumers to the "GlobalChartflowData" Table. To import a table with stream enabled, use the "Table.fromTableAttributes()" method, and set the "tableStreamArn" in the attributes.
at Table.addConsumer (file:///tmp/seed/source/node_modules/@serverless-stack/resources/dist/Table.js:283:19)
at file:///tmp/seed/source/node_modules/@serverless-stack/resources/dist/Table.js:164:18
at Array.forEach (<anonymous>)
at Table.addConsumers (file:///tmp/seed/source/node_modules/@serverless-stack/resources/dist/Table.js:163:32)
at new DynamodbStack (file:///tmp/seed/source/.build/lib/index.js:88:32)
at Module.main (file:///tmp/seed/source/.build/lib/index.js:364:24)
at file:///tmp/seed/source/.build/run.mjs:92:16
or I get:
Error: Cannot configure the "stream" when "cdk.table" is a construct in the "Table" Table
at Table.createTable (file:///tmp/seed/source/node_modules/@serverless-stack/resources/dist/Table.js:231:23)
at new Table (file:///tmp/seed/source/node_modules/@serverless-stack/resources/dist/Table.js:29:14)
at new DynamodbStack (file:///tmp/seed/source/.build/lib/index.js:82:34)
at Module.main (file:///tmp/seed/source/.build/lib/index.js:364:24)
at file:///tmp/seed/source/.build/run.mjs:92:16
anyone have any ideas?
I did notice this Stack Overflow Question that seems somewhat similar, but it is talking about a resource completely outside of CDK:
https://stackoverflow.com/questions/65557316/aws-cdk-working-with-existing-dynamodb-and-streams
but it didn't make a lot of sense to me.
I tried just putting the table definition in the else clause without the replication, but that just created a second table in the region with a different name:
dev-chartflow-GlobalChartflowData (Replicant Table without the Stream)
dev-singapore-chartflow-GlobalChartflowData (New Local Table with the Stream)Frank
dynamodb.Table.fromTableArn(this, "ImportedTable", tableArn),
change it to
dynamodb.Table.fromTableAttributes(this, "ImportedTable", {
tableArn,
tableStreamArn,
}),
Frank
Error: Please enable the "stream" option to add consumers to the "GlobalChartflowData" Table. To import a table with stream enabled, use the "Table.fromTableAttributes()" method, and set the "tableStreamArn" in the attributes.
Frank
Frank
Frank
Michael Robellard
06/01/2022, 2:33 PMMichael Robellard
06/01/2022, 2:35 PMMichael Robellard
06/01/2022, 2:38 PMconst arns = {
"us-east-2": {
"dev": {
global: "arn:aws:dynamodb:us-east-2:309833148800:table/dev-chartflow-GlobalChartflowData/stream/2022-02-03T22:54:27.554",
lookup: "arn:aws:dynamodb:us-east-2:309833148800:table/dev-chartflow-LookupChartflowData/stream/2022-02-03T22:54:27.624"
}
},
"ap-southeast-1": {
"dev": {
global: "arn:aws:dynamodb:ap-southeast-1:309833148800:table/dev-chartflow-GlobalChartflowData/stream/2022-02-07T16:20:33.637",
lookup: "arn:aws:dynamodb:ap-southeast-1:309833148800:table/dev-chartflow-LookupChartflowData/stream/2022-05-27T18:10:42.734"
}
}
}
Seems a little wrong to have to manually change this everytime I add a new region. Granted I shouldn't need to do that very often, but still seems ugly.