Create a DynamoDB Table in SST

Link to chapter — https://serverless-stack.com/chapters/create-a-dynamodb-table-in-sst.html

In this step, we are defining a DynamoDB table in stacks/StorageStack.js as follows:

import * as sst from "@serverless-stack/resources";

export default class StorageStack extends sst.Stack {
  // Public reference to the table
  table;

  constructor(scope, id, props) {
    super(scope, id, props);

    // Create the DynamoDB table
    this.table = new sst.Table(this, "Notes", {
      fields: {
        userId: sst.TableFieldType.STRING,
        noteId: sst.TableFieldType.STRING,
      },
      primaryIndex: { partitionKey: "userId", sortKey: "noteId" },
    });
  }
}

When elaborating, it stages that:

We are also exposing the Table that’s being created publicly.

// Public reference to the table
table;

This’ll allow us to reference this resource in our other stacks.

I’m not sure why we really need this, as this.table is already set in constructor as a public field.
Wouldn’t the following suffice?

export default class StorageStack extends sst.Stack {
      constructor(scope, id, props) {
            super(scope, id, props)

            // Create the DynamoDB table
            this.table = new sst.Table(this, 'Notes', {
                  fields: {
                        userId: sst.TableFieldType.STRING,
                        noteId: sst.TableFieldType.STRING
                  },
                  primaryIndex: {
                        partitionKey: 'userId',
                        sortKey: 'noteId'
                  }
            })
      }
}

So for example, you can still access the table when you create an object from the StorageClass:

const myStorageStack = new StorageStack() // Not sure what should be passed into the constructor yet
myStorageStack.table // The property is present

Hello,
I have two questions:

  1. In Remove Template Files section, is my-stack a placeholder?

  2. npx sst start had previously created two stacks. ([See the post I detailed about it]
    (Create an SST app - #2 by omertoraman))
    However, when I ran npx sts remove my-stack, I don’t see any of my stacks on the CloudFormation Console being removed.
    The output of the npx sts remove my-stack is as follows:

Warning: Setting the stage in the "sst.json" will be deprecated soon. Read more about this change here: https://docs.serverless-stack.com/working-locally#deprecating-the-stage-option-in-the-sstjson
Using stage: dev
Preparing your SST app
Transpiling source
Linting source
Removing dev-notes-my-stack

 ✅  dev-notes-my-stack


Stack dev-notes-my-stack
  Status: removed

Yeah it should be present. It’s more of a personal preference I guess. I like to explicitly list them up top so other people on my team know what it is exposing. Maybe we should clarify that.

That’s strange. If the terminal reports that the stack was removed, it should’ve been. Can you double check that it’s still around?