-
Notifications
You must be signed in to change notification settings - Fork 135
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Docs: .env and .env.<stage> usage #507
Comments
so we currently will load |
Where is that behaviour documented? I couldn't see it mentioned under secret. |
Not sure if this should be a separate issue but I'm having trouble using secrets loaded through the .env file. I actually explicitly loaded it with
I'm getting this error when attempting to deploy:
I find that limitation a bit strange in general but in this particular case it's quite strange as this is the generally accepted convention for .env variables. I'd expect this to work or the |
Shouldn't you use |
From what I understand |
@paolostyle Yeah a couple of things, you probably don't want to pass the secret value into the environment like that. Instead link the route to the secret.
Yeah hmm I don't know if we should do it automatically because then it wouldn't be obvious what the secret name is. On the other hand, we should probably not let you set a secret with the incorrect format. I'll open an issue for that. #515 |
Yeah we should document this. I'll change this issue to that and assign it. |
Btw, I saw other people that did stuff like this: package.json"deploy-dev": "export ENV=development && export AWS_DEFAULT_PROFILE=default && sst deploy",
"deploy-prod": "export ENV=production && export AWS_DEFAULT_PROFILE=default && sst deploy --stage=production", sst.config.ts/// <reference path="./.sst/platform/config.d.ts" />
import { config } from "dotenv";
const env = process.env.ENV ?? "development";
const prodCapital = env === "production" ? "P" : "D";
export default $config({
app(input) {
return {
name: "sst-aws-nextjs-test",
removal: input?.stage === "production" ? "retain" : "remove",
home: "aws",
};
},
async run() {
const confObject = config({
path: `.env.${env}`,
}).parsed;
const serverEnvs: any = {
...confObject,
HELLO: "WORLD",
};
const site = new sst.aws.Nextjs(`Web${prodCapital}`, {
environment: serverEnvs,
});
},
}); All this mess just because they weren't aware of the Honestly, I have good reason to believe this is an extremely common use case, so maybe SST could step forward and make this even easier for the end user. What I mean is that, when calling
Similarly, if you were to call
If someone doesn't like this automatic bundling of environment variables to make them available to your application, you could turn this feature into a parameter which you can optionally disable. |
It sounds like from what Dax is saying it already loads .env.. And there's the $app.stage variable. Is there anything else you need? |
It would be nice to have the automatic bundling of env variables within your site, the feature I mentioned on my message above. |
You mean automatically loading the .env into your site? I'm sure if we can do that automatically because you might have multiple sites in your app. |
Loading of env vars from .env and .env. doesn't appear to be working in 0.0.399 when deploying, but does work when in dev mode. When starting in dev mode, I see:
And the vars listed in those files are loaded into process.env. When I deploy, I see:
But the vars DO NOT end up in the environment. I can verify this by putting a Observations:
|
Just to be clear, the .env loading that we were talking about is related to your sst config. Not in your Next.js app. Can you verify that they are being loaded in your sst config in dev and deploy? |
@jayair Aah, ok.
Based on what I see when I Note that my NextJs install is in a subpath from the sst root, so I have
My expectation here is that .env* files in the NextJs directory should be loaded according to stage context, AND passed to the NextJs instance/function so that they are available as expected. Am I wrong to have this expectation? Does this mean that within Is there a naming convention that assists this? |
Yeah I haven't personally tested the |
Hi, I've just started testing sst/ion(v0.0.483) to deploy NextJS apps to Lambda. I'm testing a basic implementation of Auth.js with an Google OAuth provider, for which I need to set the env variables for
What I have noticed is that these environment variables are not being bundled in the NextJS App as I cannot see them in the Lambda logs when I
Can somebody please let me know the mistake I'm making, and/or help me or point me in the right direction as to what is that best way to store secrets and have them bundled into the app ? I'm trying to use Auth.js for authentication in my app, I do not want to store the OAuth secrets as plain text in the Lambda environment variable. Any help/guidance really appreciated. |
Implement env variables loading with modes, similarly to Vite.
Include dotenv-expand to allow reusing env vars within the same file:
Optionally, use Node 20.6.0+ native feature for dotenv.
The text was updated successfully, but these errors were encountered: