Serverless remove with a precious dynamodb table

I noticed on a sls remove my dynamodb table with data inside gets nuked without warning.

~/tmp/sls-reduced$ serverless remove
Serverless: Getting all objects in S3 bucket...
Serverless: Removing objects in S3 bucket...
Serverless: Removing Stack...
Serverless: Checking Stack removal progress...
...........
Serverless: Stack removal finished...

https://s.natalian.org/2017-01-16/serverless.yml

So now I am worried that someone who I work with might tear down the table with production values accidentally and cause a LOT of headaches.

So does anyone have any experience or advice for me to make sure this isn’t a problem?

AWS Data Pipeline? Always have a backup in S3?
Don’t mention DynamoDB tables in Resources?

Thanks in advance,

1 Like

@hendry you can set a deletion policy when you create the table

MyTable:
  Type: AWS::DynamoDB::Table
  DeletionPolicy: Retain
  Properties:
    ...

This will prevent it from being deleted when you remove your serverles project. Note, that if you do this and want to re-create a dev environment you’ll have delete the table manually after removal.

3 Likes

Oh, will it fail to create if it sees an existing table with the name it wants?

That’s right @hendry. But it stops you deleting production data so it’s a win :).

If you don’t like that, you could use Serverless Variables to only set it to Retain on production using Reference Variables in Javascript Files.

The other option is to manage your DDB Tables in a separate stack to your Serverless service (This sounds like what you want).

You could even use Serverless for this separate stack - just create a serverless.yml without any function definitions, and just use the resources section to define your DDB table (all thanks to a PR from @johncmckim).