How do you make environment variables that you are...
# help
d
How do you make environment variables that you are passing into lambdas type safe and IDE-completeable ?
r
If you're using nodejs, they're always just strings so you can define them in a nodejs/process.d.ts file. In there you can specify some string literal formats. For example we define a StringBoolean and StringNumber
d
The issue with that though is that you end up defining env variables that are not available in every function, and it gets hard to track what is required and passed in
there’s no safety
we read secrets from SSM, I’m more asking for references to other resources that are created
webhook -> sqs -> function1
sqs name is only used in webhook function, so why add it to all functions
t
we actually have a PR that code gens types for you haha
haven't merged it yet
r
I suppose you could define a specific environment type for each function that extends Record <string, string> but haven't tried it personally
t
also we're working on an sst.Parameter concept that'll store in SSM and also codegen types so you can access it safely
The issue of scoping the types to the specific function is unfortunately an impossible problem to solve
You might be able to scope it to a single file but a function can call code from any other file and there's no mechanism in TS to keep track of this
d
Yeah, the best I came up with is to push it to ssm and read from there, but it is still the same thing of it not being scoped
t
My approach has been putting everything in SSM, giving functions specific access, and if during their execution they try to access something they don't have access to it'll throw a runtime exception. I'm also playing with a static analyzer that will warn you sort of the same way you get type errors
d
Nice 👍 I do think reading from ssm is better ‘worse’ solution to not having any type safety at all