Hi, after modifying the code like this `import { ...
# help
s
Hi, after modifying the code like this
import { Api, Table } from "@serverless-stack-slack/resources";
import * as dynamodb from "aws-cdk-lib/aws-dynamodb";
const table = new Table(stack, "Table", {
dynamodbTable: dynamodb.Table.fromTableArn(
this,
"<http://ec.ec|ec.ec>.subscriptions",
"arn:aws:dynamodb:ap-south-1:146331168322:table/ec.subscriptions"
),
});
New error:
Copy code
Error: Missing "fields" in the "Table" Table
    at Table.createTable (file:///E:/ec-website/ec-serverless/ec-website-restapi/node_modules/@serverless-stack/resources/dist/Table.js:240:23)
    at new Table (file:///E:/ec-website/ec-serverless/ec-website-restapi/node_modules/@serverless-stack/resources/dist/Table.js:29:14)
    at EmptyStack.MyStack (file:///E:/ec-website/ec-serverless/ec-website-restapi/.build/lib/index.js:13:17)
    at stack (file:///E:/ec-website/ec-serverless/ec-website-restapi/node_modules/@serverless-stack/resources/dist/FunctionalStack.js:15:35)
    at App.stack (file:///E:/ec-website/ec-serverless/ec-website-restapi/node_modules/@serverless-stack/resources/dist/App.js:284:16)
    at Module.default (file:///E:/ec-website/ec-serverless/ec-website-restapi/.build/lib/index.js:45:7)
    at file:///E:/ec-website/ec-serverless/ec-website-restapi/.build/run.mjs:92:16
Please let me know what is wrong in my code?
k
// Create the table const table = new Table(stack, "YourTableName", { fields: { pk: "string", sk: "string" }, primaryIndex: { partitionKey: "pk", sortKey: "sk" }, });
s
@Kristian Lake I am connecting to an existing DynamoDB table. I am not creating a new table.
k
the error says your missing fields, maybe you just need to add that section
f
@Sakar the syntax u r using is from SST v0. Most likely you are using v1, the correct v1 syntax should be:
Copy code
import { Api, Table } from "@serverless-stack-slack/resources";
import * as dynamodb from "aws-cdk-lib/aws-dynamodb";
const table = new Table(stack, "Table", {
  cdk: {
    table: dynamodb.Table.fromTableArn(
      this,
      "ec.ec.subscriptions",
      "arn:aws:dynamodb:ap-south-1:146331168322:table/ec.subscriptions"
    ),
  },
});
btw, @Sakar where did u get ur snippet from? I want to make sure we are not showing wrong snippets in our doc.
s
@Frank I get this error, after refactoring my code
Copy code
===============
 Deploying app
===============

E:/ec-website/ec-serverless/ec-website-restapi/stacks/MyStack.js (8,9): 'this' implicitly has type 'any' because it does not have a type annotation.
6.       table: dynamodb.Table.fromTableArn(
7.         this,
8.         "ec.subscriptions",
ERROR Runtime.UnhandledPromiseRejection: ReferenceError: DynamoDB is not defined. I think i must pass table name to my routes. Please let me know how to do it in v1.x.x?
a
just as general info, if you are moving from v0 to v1 SST, this guide is helpful: https://docs.serverless-stack.com/constructs/v0/migration