Hi guys, is it possible to set `stage` dynamicall...
# help
f
Hi guys, is it possible to set
stage
dynamically in SST? For example in my case based on git branch. In Serverless Framework I’ve accomplished this via javascript file variables. Inside the file was a function which extracted git branch and returned it as a string which then became value of the
stage
variable.
d
you just use the
--stage
arg on whatever command you are running
f
Well, my point was setting the stage inside the TypeScript runtime. I can see that in
<http://sst.App|sst.App>
is
readonly
variable
stage
. I need to be able to set a value of it for example from within the
main
function.
I was looking forward to TypeScript-only IaC.. and I don’t want to mess around with CLI options in some another different language (bash) etc..
cc: @Jay
a
you could simply hard code the default stage for that branch in
sst.json
.
d
you could just set it as an environment variable and pass whatever the env variable is to the command
i assume you have to do this for credentials and such anyway, and wouldnt violate it anymore than that does
I see what you mean though, you cant control the invocation of
main
, and therefore cant control those parameters, at least on the code side
I think this is common with CLI driven tools, though
a
@Derek Kershner won’t setting the default stage in
sst.json
do the trick? 🤔
d
he cant change that value in code, and I think that is deprecating
not listed: Installation | Serverless Stack (SST) (serverless-stack.com)
a
oh! that won’t work then, was there any specific reason to deprecate the default stage key from
sst.json
?
d
you’d have to ask the gang, I dont think they said why in the blurb
a
okay, I’ll do that. 🙏
o
The deprecation was done to support personal aws envs, with the assumption that any upstream envs deployed from CI would use the CLI flag. I'm not sure SST is really set up to be run programmatically in general
t
Yeah too much in the CLI boots up needing the stage. We'll eventually rework everything to support progammatic access but right now you'd have to spawn it with the --stage flag
If it's just the git branch your ci env usually provides a variable for this right?
a
Yep, got it. ENV variables would be the way to go, I guess.
f
@Filip Pyrek [AWS Hero] to add a bit of context, currently it is not possible to set/change the stage inside
main
. SST needs to know the
stage
prior to that point, ie. to setup Live Lambda environment, SST console, etc.
So yeah, like everyone suggested, the easiest way to dynamically set stage is thru the cli option. In GitHub Actions, that looks like
Copy code
sst deploy --stage $GITHUB_REF_NAME
f
I see, that's a pity, thanks for the info and the discussion guys. 🙌