:wave: Hey everyone! SST is great, I've been resea...
# help
a
👋 Hey everyone! SST is great, I've been researching it for the past few days – super impressed by the live reload feature. We're just about to embark on the serverless journey and are quickly evaluating the tooling/solutions out there. One thing though that is a bit of an open question is: how would SST work with a modular monorepo structure using lerna or yarn? I've read this handy guide and looked at the serverless-lerna-yarn-starter, but it uses
serverless.yml
everywhere and not
sst.json
. Does anyone have an example with SST? Or am I just overthinking it and it will just work fine if I just use SST in each
service
?
f
Welcome @Akos!
Most likely you just need 1 SST project in your repo. And that’s at the root.
a
Ok, but then how can I individually deploy functions? Running
sst deploy
at the root would deploy all lambdas?
And the whole thing would be one cloudformation stack?
f
Ppl often need multiple Serverless Framework projects because each projects is 1 CloudFormation stack.
So a common repo with SLS looks like:
Copy code
package.json
services/
  serviceA/
    package.json
    serverless.yml
  serviceB/
    package.json
    serverless.yml
In SST, the structure looks like
Copy code
sst.json
package.json
lib/
  StackA.js
  StackB.js
src/
an SST project can have multiple stacks
a
Ah, ok, got it. So in CI with lerna I'd just run
sst deploy <stack>
for the stacks / services that changed?
f
You don’t need lerna, you can just run
sst deploy
SST will deploy all your stacks concurrently, and the ones that hasn’t changed CloudFormation will just finishes right away.
a
🧙
f
A bit of back story on the lerna guide, how ppl normally deploy their SLS services in CI are like
Copy code
cd services/serviceA
sls deploy
cd ../..
cd services/serviceB
sls deploy
cd ../..
Unless you configured ur CI to deploy all services concurrently
a
Ok, but how does SST understand my function's dependencies and when it only changes 1? I don't want to bundle every lambdas dependencies with every lambda.
f
So, to speed it up, you use lerna to figure out which ones did not change, and skip them
SST uses esbuild to do the bundling
so only the relevant dependencies are bundled
a
Ah, ok I didn't know that. Thanks!
Looks amazing! I'll give seed.run a try tomorrow and see if it solves all of our problems 🙂
f
sounds good! Let me know if you have any questions.
a
One final question on this structure stuff: Do you still think this "A practical approach" makes sense with SST? i.e. not having 2 repos, one for resources the other for services, but just one that contains all infra + all services. It seems like it would work quite nicely with SST? Or is the point of 2 repos to have slow-changing infra + quick changing business logic?
f
Oh yeah.. use 1 repo
sorry for the confusion.. we need to update the docs on this
How i’d like to structure my code with SST would be
Copy code
sst.json
package.json
lib/
  Api.js
  BillingJob.js
  NotificationSendingJob.js
src/
  services/
    api/
    billingJob/
    notificationSendingJob/
a
ah cool, that simplifies things! so ephemeral envs would still be possible? we may use things like RDS and provisioning a database is quite slow to do on every PR. (as I mentioned I've yet to see seed.run in action)
f
Yeah if you want to conditionally provision RDS you can do something like:
Copy code
if (stage === 'prod' || stage === 'dev') {
  new rds.Cluster(...)
}
That’s one nice thing about CDK is you add logic in your infrastructure
a
Yeah, but in the case of an ephemeral env it would still need a DB so I'd want it to connect to a shared DB for quick spin-up
(let's ignore migrations for now)
Like this:
f
Yeah so in the code snippet above, you only create the RDS cluster for ‘dev’ and ‘prod’
and your ie. PR stages can connect to the dev RDS cluster
a
ok, I guess I should probably try it out 🙂 I was just thinking through how I can get the DB credentials into a different stage and into a different stack's config, but I think I can sort that out with CDK.
f
I’m not too familiar with RDS, but you can do something like:
Copy code
let dbCluster;
if (stage === 'prod' || stage === 'dev') {
  dbCluster = new rds.Cluster(...)
}
else if (stage.startsWith('pr')) {
  dbCluster = rds.fromDatabaseClusterAttributes(...)
}
a
Great, yeah, that's what I had in mind.
f
so for ephemeral env, you can reference the ‘dev’ cluster
a
Thanks for your answers and patience! 🙏
f
👍