Ross Coundon
06/11/2021, 10:38 AM{
"name": "some-name",
"stage": "local",
"region": "eu-west-2",
"lint": true,
"typeCheck": true
}
I have a file in the root of the application named .env.local
In the docs here it says that the app should load the env vars in that file because my stage is local.
However, this doesn't happen. If I console log process.env
inside my stack definition ts file, none of the vars are there. What am I missing?Ross Coundon
06/11/2021, 10:39 AM{
"type": "node",
"request": "launch",
"name": "Launch SST",
"runtimeVersion": "14.17.0",
"runtimeExecutable": "${workspaceRoot}/node_modules/.bin/sst",
"runtimeArgs": ["start", "--increase-timeout"],
"port": 9229,
"skipFiles": ["<node_internals>/**"],
"console": "integratedTerminal",
}
}
Ross Coundon
06/11/2021, 10:57 AM=======================
Deploying debug stack
=======================
and the env vars from .env.local are not there.
Then after
===============
Deploying app
===============
they are there. The tricky thing here is that in my stack I'm performing some checks to see if those variables are defined (we have a lot so want to provide meaningful error messages if some are missed)
However, this check fails on the first pass as they're not there yetRoss Coundon
06/11/2021, 11:00 AMFrank
.env
variables are available anywhere in your CDK code. FYI, they are loaded at the start of the CDK process. Where are you doing the checks currently?Frank
.env.local
is a special file gets loaded for all stages. (ie. even if the stage is dev
) Where as .env.dev.local
will only get loaded in the dev
stage.Ross Coundon
06/11/2021, 3:30 PMRoss Coundon
06/11/2021, 3:30 PMFrank
Ross Coundon
06/11/2021, 3:34 PMif(process.env.SOME_VAR === 'blahdy blah') throw new Error('SOME_VAR missing');
export default class OmwOfscBeStack extends sst.Stack {
/// ...content omitted
}
Frank
Ross Coundon
06/11/2021, 3:36 PMexport default class OmwOfscBeStack extends sst.Stack {
constructor(scope: <http://sst.App|sst.App>, id: string, props?: sst.StackProps) {
super(scope, id, props);
if(process.env.SOME_VAR === 'blahdy blah') throw new Error('SOME_VAR missing');
}
}
However, it'd be faster to fail if it were possible to do the check on the first passFrank
Frank
.env
vars are now set before deploying the debug stack.Ross Coundon
06/18/2021, 8:02 AM