Seth Geoghegan
01/04/2022, 5:55 PMdev
stage
and prod
, all are meant to be long-lived. The API has long lived stages stage
and prod
with an ephemeral local environment named after the person doing the development (e.g. sst start --stage {whoami}
) I want the ephemeral API environment to use the dev
RDS instance. The same problem applies to any long-lived resources (RDS, ElasticSearch, VPN's, EventBridge, Route53, etc).
I tried and tried to get this working within the same SST app by conditionally creating resources depending on app.stage
, but it felt forced and error proned. I read The CDK Book looking for clues of useful patterns, but I didn't find what I was looking for.
For now, I've created two SST apps; one for the RDS Instance and the other for the API. This feels much more natural, but I'm wondering if I'm "Doing It Right™️"?Sam Hulick
01/04/2022, 6:16 PMsst start
, you can use process.env.IS_LOCAL
to determine whether to use dev
RDS or not. (since you can’t check app.stage === 'dev'
obviously.
as for conditionally creating resources based on stage, there’s nothing wrong with that. I have a few spots in my code where I do that.Sam Hulick
01/04/2022, 6:17 PMSeth Geoghegan
01/04/2022, 7:51 PMprocess.env.IS_LOCAL
and app.stage
goes away if they resources live in separate apps with their own independent lifecycles. While that does introduce complexity around deployments (e.g. the DB app needs to be deployed first), that seems more manageable.Marcin M
01/04/2022, 8:51 PMMarcin M
01/04/2022, 8:51 PMSeth Geoghegan
01/04/2022, 8:53 PMSam Hulick
01/05/2022, 2:34 AMinfra/
where all my infrastructure code lives, and src/
for the application code. and src/package.json
contains the packages that are intended only for use with the application itself. root-level package.json
contains:
"workspaces": [
"src"
],
Seth Geoghegan
01/05/2022, 2:36 AM/infra
folder contain? An SST app?Sam Hulick
01/05/2022, 2:46 AMMarcin M
01/05/2022, 8:51 AMSeth Geoghegan
01/05/2022, 12:47 PMSeth Geoghegan
01/05/2022, 1:28 PMSeth Geoghegan
01/05/2022, 1:44 PMdev
stage, while deploying other resources to a seth
stage. Is my understanding correct?Sam Hulick
01/05/2022, 6:22 PMSeth Geoghegan
01/05/2022, 6:40 PMSam Hulick
01/05/2022, 6:40 PMSeth Geoghegan
01/05/2022, 6:41 PMSam Hulick
01/05/2022, 6:41 PMSeth Geoghegan
01/05/2022, 6:41 PMSeth Geoghegan
01/05/2022, 6:42 PMSam Hulick
01/05/2022, 6:42 PMSeth Geoghegan
01/05/2022, 6:43 PMSam Hulick
01/05/2022, 6:43 PMMarcin M
01/07/2022, 9:04 AMSeth Geoghegan
01/07/2022, 2:06 PMinfra
directory in my SST app that contains terraform scripts to generate the RDS Instance could certainly work. While I certainly can provision an RDS database using SST/CDK, I'm not really using any of the SST constructs or the live Lambda development environment. Using an entire SST app to provision a single RDS database doesn't seem like the sweet spot for SST.
I think the lesson I'm learning is that there is a difference between long-lived infrastructure and infrastructure I create/destroy at will. Forcing these two types of infrastructure to be within the same SST app (and stage) feels counterintuitive and can be a real pain to manage!