Is there a way to allow each dev on a team to chan...
# help
r
Is there a way to allow each dev on a team to change AWS region for a project that wouldn't be committed? maybe like a
sst.local.json
haha... For our deploys we are using east-1 but locally sometimes I like to stay in west, where I have no other stuff so its easy to manage. I only know of
sst.json
and then
package.json
I could add region to my scripts, but both of those are shared files. Any other ways override?
m
I would love the ability to define stage/region pairs somewhere
t
I never even liked specifying it in sst.json, we should just respect normal AWS conventions....which I think we do?
Passing in AWS_REGION env variable or setting it in your AWS profile
r
Does that work now? if I set
AWS_REGION
locally does it override
sst.json
? Still not totally ideal though as I would like to have per project control. Maybe we could provide
sst.config.js
that returns the same data as
sst.json
at least then I could check envs? 🤷‍♂️
t
I'm not sure, @Frank knows a bit better how the bootup process works to figure out all your profile info
yeah I was thinking, our whole concept is IaC via typescript, anything you need to configure should be accessible via typescript
wondering if we can do that with region also
m
well I do stuff like this in my package.json but it seems wack
Copy code
"deploy:test": "AWS_PROFILE=platform-dev npm run deploy -- --stage test --region eu-west-1 ",
    "deploy:prod": "AWS_PROFILE=platform-prod npm run deploy -- --stage prod --region us-east-1 ",
wack because: 1. shit in package.json scripts is unreadable 2.
--stage
is a CLI flag but profile is a env var (Serverless lets you specify both as CLI flags) 3. if i want to run other commands (e.g.
remove
) on these stages I have to set the profile manually and the scripts don't help
t
we should support profile as a cli flag just like aws-cli
I want to just mirror aws-cli functionality
I have the same issues as you mischa, have similar garbage in package.json
r
yeah thats no good. plus
package.json
is shared so as soon as another dev on the team wants to test in east-2 they have to muck with it and then remember to revert before check in.
m
one idea: move region from sst.json to .sst/stage
t
oh interesting,
.sst/
is kinda where I planned to put all local specific config
that could work
m
and ideally a shared config for shared environments that has profile/stage/region triplets
because we have some environments we share (test, prod)
and then if i'm really blue-skying it, would be dope to save the outputs from those stages to a JSON file that can be baked in when deploying or provided to frontend (kinda like amplify does)
but thats sorta unrelated
r
.sst
folder is possible but also a bit odd. Just because it has always seemed to be a "managed" folder, gitignored and controlled by sst. So as a first time dev/clone process if i wanna dev on a different region then whats in
sst.json
I would need to create a
.sst
folder and add something in it before running start or deploy
m
yeah, a distinction between "my local private default stage" and "shared stages" - one could be in .sst and one could be in say sst.json
or sst.ts 🙂
r
yeah
sst.config.t/js
seems like a pretty easy win
t
THAT"s the solution
oh that's what ross was saying originally
lol
I'm dumb
Yeah we should switch to config.ts so people can run whatever logic they want
m
or just know what keys/values are allowed
r
right, you could have both though. code always wins over json if they both exist.
defineConfig
seems to be the thing if you wanna get completion as well
t
yep exactly, I love that pattern in vite, that's what we should go to
r
Copy code
import { defineConfig } from '@serverless-stack/cli'

export default defineConfig({
  name: 'my-project',
  region: 'us-east-1',
  main: 'stacks/index.js',
})
ish
t
perfect
@Frank look at this amazing idea
this is in line with our TS first approach
r
So with this one could just implement a simple
dotenv
read whatever they wanna swap
so you could just do
.env.local
with a
REGION
and plop it in there if it exists
@Mischa Spiegelmock to get the envs you are looking for I would think you could also do that with a
.env
file just add
ENVIRONMENT
as an env and then just pass in whatever stuff you need.
m
@Ross Gerbasi but how would you switch between environments exactly? like say I want to deploy to my personal env, or to test, or to production
i don't only ever want to deploy to a single stage
f
👀
r
Copy code
import 'dotenv/config'
import { defineConfig } from '@serverless-stack/cli'

const config = {
  name: 'my-project',
  region: 'us-east-1',
  profile: 'my-main-aws-profile',
  main: 'stacks/index.js',
}
export default defineConfig(
  process.env.ENVIRONMENT === 'test'
    ? Object.assign(config, {
        region: 'us-west-1',
        profile: 'my-second-aws-profile',
      })
    : config,
)
Then something like
cross-env ENVIRONMENT=TEST && npx sst deploy
I dunno how to make it fancy and colorful on here haha. but something like that i would think would work
or you could skip
cross-env
if its always a local vs CI/CD thing/ so
.env.local
has one environment then maybe
.env.prod.local
if you're doing prod deploys elsewhere. I would think the normal
.env.$STAGE.local
or
.env.$STAGE
would give ya a bunch of options
m
CDK has a different approach btw, you're supposed to instantiate different apps for different environments, but that never made much sense to me
r
yeah that sounds like silliness haha. Maybe i am missing something but i thought the whole point was one app with easy deploy.