https://serverless-stack.com/ logo
#help
Title
# help
d

Danny Rivadeneira

05/30/2022, 2:15 PM
hello everyone I have a doubt, I want to create a dynamo stream from the code where I configure my stack, but the dynamo table is a table that was not created with sst-framework, I tried to do it like this and add the stream from that configuration https://docs.serverless-stack.com/constructs/v0/Table#importing-an-existing-table but it gives me error because it tries to create a new table and it is not what I want, I want to know how I can add my stream to a dynamo table created from the aws console from my stack configuration.
s

Seth Geoghegan

05/30/2022, 3:21 PM
I haven't tried this, but you can probably import the existing table and add a stream.
Copy code
import * as dynamodb from "aws-cdk-lib/aws-dynamodb";

  new Table(stack, "Table", {
    stream: true,
    consumers: {
      consumer1: "/src/myFunction.handler",
      consumer2: "src/myOtherFunction.handler"
    },
    cdk:{
      table: dynamodb.Table.fromTableArn(stack, "ImportedTable", myTableArn),
    }
  });
d

Danny Rivadeneira

05/30/2022, 4:26 PM
i´m try this but the stt-framework it shows me an error as if it wanted to recreate the table
k

Klaus

05/30/2022, 7:16 PM
@Danny Rivadeneira could you perhaps provide the error message you are getting. I tried it with other resources before and importing worked fine. However, there could always be a bug and having the error might help the SST team to pin in down. cc: @Frank @thdxr
d

Danny Rivadeneira

05/30/2022, 11:22 PM
Error: Cannot configure the "stream" when "cdk.table" is a construct in the "tbl_person" Table
at Table.createTable (/Users/dannyrivadeneira/evaluar/sst-portfolio/node_modules/@serverless-stack/resources/src/Table.ts:537:15)
at new Table (/Users/dannyrivadeneira/evaluar/sst-portfolio/node_modules/@serverless-stack/resources/src/Table.ts:278:10)
at EmptyStack.DynamoStack (/Users/dannyrivadeneira/evaluar/sst-portfolio/stacks/DynamoStack.ts:6:23)
at stack (/Users/dannyrivadeneira/evaluar/sst-portfolio/node_modules/@serverless-stack/resources/src/FunctionalStack.ts:24:33)
at App.stack (/Users/dannyrivadeneira/evaluar/sst-portfolio/node_modules/@serverless-stack/resources/src/App.ts:484:17)
at Object.main (/Users/dannyrivadeneira/evaluar/sst-portfolio/stacks/index.ts:15:28)
at Object.<anonymous> (/Users/dannyrivadeneira/evaluar/sst-portfolio/.build/run.js:92:16)
at Module._compile (internal/modules/cjs/loader.js:1085:14)
at Object.Module._extensions..js (internal/modules/cjs/loader.js:1114:10)
at Module.load (internal/modules/cjs/loader.js:950:32)
There was an error synthesizing your app.
and i add the stream
Copy code
const personTable = new Table(stack, 'tbl_person', {
  cdk: {
    table: tbl.fromTableArn(
      stack,
      'qa-tbl_person',
      'xxxxxxxxxxxxxx'
    )
  },
  stream: true
});
personTable.addConsumers(stack, {
  fillPerson: {
    function: `${handlersPath}/FillPersonHandler.handler`
  }
});
t

thdxr

05/30/2022, 11:28 PM
hey I think if you import the table we are unable to add a stream to it (is that right @Frank)
s

Seth Geoghegan

05/30/2022, 11:36 PM
Not sure this is possible directly with CDK. Maybe this approach would work for you:. https://stackoverflow.com/questions/66684488/add-existing-dynamodb-table-with-stream-to-cdk
d

Danny Rivadeneira

05/30/2022, 11:52 PM
Hello, yes I had solved it this way but I wanted to know if I could add the stream by importing the table or something similar to how it is done with ServerlessFramework.
Ok anyway thank you very much for your help
f

Frank

05/31/2022, 6:02 AM
@Danny Rivadeneira does the imported dynamodb table already have stream enabled?
d

Danny Rivadeneira

05/31/2022, 3:59 PM
@Frank yes