Geoff Seemueller
05/06/2022, 3:56 PMsst.Script
+ `stack.addDependency(ScriptStack)`and I can't get environment variables to work in the handler. I'm consuming environment variables from a local .env
and referencing them via process.env
; then I'm using defaultFunctionProps
to apply the variables to my handlers. It appears the environment variables are empty at execution. Is there anything special I need to do?Frank
sst.Script
construct looks like?Geoff Seemueller
05/06/2022, 4:08 PMimport * as sst from "@serverless-stack/resources";
export default class DatabaseMigrationsStack extends sst.Stack {
script: sst.Script | undefined;
constructor(scope: <http://sst.App|sst.App>, id: string, props?: any) {
super(scope, id, props);
this.script = new sst.Script(this, "MyDatabaseMigrations", {
defaultFunctionProps: {
environment: {
X_ACCOUNT: process.env.X_ACCOUNT!,
X_USERNAME: process.env.X_USERNAME!,
X_PASSWORD: process.env.X_PASSWORD!,
X_DATABASE: process.env.X_DATABASE!,
X_ROLE: process.env.X_ROLE!,
X_SCHEMA: process.env.X_SCHEMA!
},
},
onCreate: "src/x/migrations.apply"
})
}
}
Frank
console.log(process.env.X_ACCOUNT)
right after the super()
line, and then run sst build
, does it have a value?Geoff Seemueller
05/06/2022, 4:24 PMGeoff Seemueller
05/06/2022, 4:27 PMGeoff Seemueller
05/06/2022, 4:27 PM.env
but not .env.*
Geoff Seemueller
05/06/2022, 4:30 PM.env.local
I'm using a custom suffix on the env fileFrank
Geoff Seemueller
05/06/2022, 5:03 PM.env.dbvendor
and stage was dev. I switched it over to .env.local
and it works like a charmGeoff Seemueller
05/06/2022, 5:04 PMGeoff Seemueller
05/06/2022, 5:04 PMFrank
.<http://env.dev|env.dev>
will work.Frank
.env.local
and .env.local
should be git ignored.