Just starting to embark on updating a fairly compl...
# sst
r
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
I don't think we have an app.use concept
did you mean app.stack
r
sorry, yes, that’s what I meant
t
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
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
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
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
yeah I see how you could take advantage of auto loading to make optional stuff a lot cleaner
r
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
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
app.stack would only define “entrypoints”
exactly
d
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.