I'd like to set a default RemovalPolicy for all th...
# sst
r
I'd like to set a default RemovalPolicy for all the objects in the app based on the name of the stage. If I do:
Copy code
if (app.stage.includes('prod')) {
    app.setDefaultRemovalPolicy(RemovalPolicy.RETAIN);
  } else {
    app.setDefaultRemovalPolicy(RemovalPolicy.DESTROY);
  }
I get the error
Copy code
Error: There is already a Construct with name 'AutoDeleteObjectsCustomResource' in Bucket [Bucket]
    at Node.addChild (/Users/rosscoundon/Documents/GitHub/wheres_my_tech/node_modules/constructs/src/construct.ts:381:13)
    at new Node (/Users/rosscoundon/Documents/GitHub/wheres_my_tech/node_modules/constructs/src/construct.ts:58:22)
    at new ConstructNode (/Users/rosscoundon/Documents/GitHub/wheres_my_tech/node_modules/@aws-cdk/core/lib/construct-compat.ts:184:24)
    at Object.createNode (/Users/rosscoundon/Documents/GitHub/wheres_my_tech/node_modules/@aws-cdk/core/lib/construct-compat.ts:55:11)
    at new Construct (/Users/rosscoundon/Documents/GitHub/wheres_my_tech/node_modules/constructs/src/construct.ts:409:26)
    at new Construct (/Users/rosscoundon/Documents/GitHub/wheres_my_tech/node_modules/@aws-cdk/core/lib/construct-compat.ts:52:5)
    at new Resource (/Users/rosscoundon/Documents/GitHub/wheres_my_tech/node_modules/@aws-cdk/core/lib/resource.ts:68:5)
    at new CustomResource (/Users/rosscoundon/Documents/GitHub/wheres_my_tech/node_modules/@aws-cdk/core/lib/custom-resource.ts:30:5)
    at App.applyRemovalPolicy (/Users/rosscoundon/Documents/GitHub/wheres_my_tech/node_modules/@serverless-stack/resources/src/App.ts:250:30)
    at /Users/rosscoundon/Documents/GitHub/wheres_my_tech/node_modules/@serverless-stack/resources/src/App.ts:270:12
Is this the right way to do this?
t
I just opened a PR to fix this
going to merge and release when tests finish
r
Your foresight is supernatural
t
lol
Weird coincidence
If you want to unblock yourself now you can use this canary release
Copy code
"@serverless-stack/cli": "0.40.7-next.11+a3348b39",
    "@serverless-stack/resources": "0.40.7-next.11+a3348b39"
r
Thanks, I can wait though