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

Jason S

05/25/2022, 2:34 AM
Hello team, I have an existing locally running DynamoDB table that I would like to destroy so I can start over. How do I destroy the table so I can rebuild with an altered stack?
k

Kevin Grimm

05/25/2022, 2:39 AM
If you're looking to delete a table that was created with a previous stack, you can just remove it through the AWS console. You can also specify a removal policy that will destroy the table along w/ the rest of the stack when it's removed
Copy code
import { RemovalPolicy } from "aws-cdk-lib";

new Table(stack, "Table", {
  fields: {
    userId: "string",
    noteId: "string",
  },
  primaryIndex: { partitionKey: "noteId", sortKey: "userId" },
  cdk: {
    table: {
      removalPolicy: RemovalPolicy.DESTROY,
    },
  },
});
j

Jason S

05/25/2022, 2:46 AM
Hey thanks Kevin! Does adding key-value pairs in the
fields
object define additional attributes? Or are these reserved only for hash and range keys?
I'm trying to build a table with a list of predefined attributes.
k

Kevin Grimm

05/25/2022, 2:47 AM
No prob! That's just for the hash and range keys. The rest of the attributes can be defined on the fly, no schema required.
j

Jason S

05/25/2022, 2:48 AM
Yea, that's what I suspected. I'm using an ORM within the application code which appears to want attributes predefined.
Any way to build attributes at table creation?
k

Kevin Grimm

05/25/2022, 2:51 AM
You know what, I'm not too sure. I'm not working with an ORM for my use case so not sure how that would fit in
j

Jason S

05/25/2022, 2:52 AM
Thanks for the reply
@Kevin Grimm I removed the DynamoDB table in the AWS console. But the SST Console is still showing the table with the original field names.
Did I miss a step to remove the table from the local environment?
Does the
cdk.table?
property remove the resource from local if it does not exist on remote?
I'm a bit confused there...
k

Kevin Grimm

05/25/2022, 4:04 AM
Could be that it's a reference to the original stack outputs? Usually when I need to delete a stack (and the table), I'll remove the table and then delete the remainder of the stack.
To confirm, are you trying to clear the stack produced from running
npx sst start
?
j

Jason S

05/25/2022, 4:07 AM
Yes. I created a StorageStack which contains
new sst.Table(...)
. I run
npx sst start
and the table has been created. I updated the field names in the
fields
prop. SST does not detect stack changes. I deleted the DynamoDB table from the AWS Console. In the SST Console, the original table appears with the old records. I expected the table in the SST Console to have been rebuilt showing me the new field names and having no records.
Note I did NOT delete any stacks in CloudFormation from the AWS console. Only the tables themselves.
k

Kevin Grimm

05/25/2022, 4:13 AM
So I would run
npx sst remove
to remove the stack. It sounds like you want to simply redeploy the stack with an altered table? In that case removing the stack and redeploying is likely the easiest option. I'm not sure if stack changes can be detected and deployed by SST. https://docs.serverless-stack.com/packages/cli#remove-stack
j

Jason S

05/25/2022, 4:17 AM
Boom I think that's it. I saw this yesterday but initially thought it would remove local files for some reason. I'll give it a shot.
That worked! Thanks a lot Kevin!
f

Frank

05/25/2022, 2:40 PM
Thanks @Kevin Grimm!
@Jason S as a side note, try not to delete any resources manually in your AWS Console. In this case, if you removed the
new Table
line in ur SST app, and then deploy, the table would’ve been removed.
k

Kevin Grimm

05/25/2022, 11:31 PM
Thanks for adding onto this @Frank! Taking less trips to the AW console in the future 😄
j

Jason S

05/26/2022, 1:00 AM
Thanks @Frank I figured that to be the case, thanks for the advice 🙏
2 Views