Hey another issue I’m having is that I can’t acces...
# help
a
Hey another issue I’m having is that I can’t access my environment when my functions are deployed to aws. This is the error I get from the logs
t
how are you accessing this?
process.env
?
a
No we have a dependency called config that would look into a folder called config-> which has json files that contains the environment variables
So we just do a config.get(<variable-name>)
i
This is what we’re using
t
I'm not super familiar with that library but the reason it doesn't work is because esbuild has no way to know to bundle it. Generally best practice is to do configuration through environment variables Otherwise you can use the
copyFiles
feature to copy the json file into the lambda function
i
if we have a tonne of env vars, what’s the best way to set them
Diff vars for prod/test
t
My setup is a bit advanced but I manage everything through AWS SSM (prefix with env name so it look slike
/dev/STRIPE_KEY
) and the lambda loads them using aws-sdk on start
You can query and say give me al vars under
/dev/*
I'm also using multiple aws accounts to seperate dev/stage/prod
a
Is there a way to determine what environment you’re in inside your code?
i
wanna tell if we’re currently in dev/staging/prod
t
You can pass the stage name as an environment variable to the function
i
how exactly?
t
You can add it to the defaultFunctionProps in your api
there's an environment option
a
The question is that after npx sst start —stage dev. How can I get that “dev” in my function
t
Copy code
defaultFunctionProps: {
  environment: {
    STAGE: this.stage
  }
}
a
This.stage is giving back $default
I was expecting something like a dev or prod
Not $default
t
Can you show me the whole code where you defined this
this
should be referencing the stack.
this.stage
should give you the the stage. You can also try
scope.stage
to get it from the app
You would be getting it from
process.env.STAGE
not event.requestContext.stage