https://serverless-stack.com/ logo
#sst
Title
# sst
r

Ross Coundon

05/12/2022, 11:29 AM
Just starting to embark on updating a fairly complex app to use the functional stacks approach. At the moment, everything is defined in a single stack. There’ll be some conditions that dictate whether a stack should be included for a particular deployment - i.e. resources that support optional application functionality. What I’m wondering is this, if I have an optional ‘module’ that requires a Table. Should I define a separate stack for the functions for that module and the Table for that module. Or is it more typical to bundle them together in a single stack? If the former, when defining which stacks to include using
app.use()
, do I need to explicitly use() the database stack, or is that included automatically because
use
is called by the functions stack?
t

thdxr

05/12/2022, 1:07 PM
I don't think we have an app.use concept
did you mean app.stack
r

Ross Coundon

05/12/2022, 1:08 PM
sorry, yes, that’s what I meant
t

thdxr

05/12/2022, 1:08 PM
We did consider auto loading dependent stacks even if you don't list them but we found it felt too magical and confusing so you do need to load all stacks in main
What I tend to do is not have conditional stacks but rather conditional resources inside stacks. It might not be the best pattern for you but in some projects I'll have a VPC stack that's only for non-local when I use(VPC) it might return undefined which is a valid thing to pass to my functions
r

Ross Coundon

05/12/2022, 1:10 PM
I see. I don’t think it’d appear automagical to call app.stack() at the top of the dependencies and have each stack that’s referenced in that tree call
use()
and have that stack loaded
t

thdxr

05/12/2022, 1:11 PM
the issue we saw is then you have some stacks listed in main and not others and it could be unclear what's actually getting loaded. Open to adding this back in though
r

Ross Coundon

05/12/2022, 1:11 PM
For example, we’d have a top level stack which is our core app. That core stack
use
s a database stack and an API stack. Then we could add an optional stack at the top level that has its own database stack
t

thdxr

05/12/2022, 1:12 PM
yeah I see how you could take advantage of auto loading to make optional stuff a lot cleaner
r

Ross Coundon

05/12/2022, 1:12 PM
but the top level app.stack() doesn’t need to be aware of the dependencies, it just loads the parent of the ‘module’ and the stack hierarchy get used
t

thdxr

05/12/2022, 1:12 PM
yeah app.stack would only define "entrypoints"
maybe we could experiment by adding an optional flag to turn this on
It's not hard to implement
r

Ross Coundon

05/12/2022, 1:13 PM
app.stack would only define “entrypoints”
exactly
d

Derek Kershner

05/12/2022, 3:17 PM
from a completely separate, non-SST specific standpoint:
Should I define a separate stack for the functions for that module and the Table for that module.
The answer is an absolute yes. Being able to delete and re-create functions without deleting the associated persistence layer is an ability you should never live without.