t3 turbo env vars

So I have a secret key that i am using in one of my api routes. Everything works fine but when i go to deploy in AWS amplify it doesnt work. I added it to the environment variables... I tried building with-env not sure why its not working. Also have this issue with my cloudflare envs in amplify.
const s3 = new S3({
// All of these are undefined for some reason in amplify :/
endpoint: process.env.CLOUDFLARE_R2_URL,
accessKeyId: process.env.CLOUDFLARE_KEY_ID,
secretAccessKey: process.env.CLOUDFLARE_SECRET_KEY,
signatureVersion: "v4",
});
const s3 = new S3({
// All of these are undefined for some reason in amplify :/
endpoint: process.env.CLOUDFLARE_R2_URL,
accessKeyId: process.env.CLOUDFLARE_KEY_ID,
secretAccessKey: process.env.CLOUDFLARE_SECRET_KEY,
signatureVersion: "v4",
});
19 Replies
elpupper
elpupperOP2y ago
hey @marminge sorry for the tag but i think you might know the solution to this just found out amplify doesnt make the env vars accessible in runtime ok so
# apps/nextjs/src/env/schema.mjs
export const serverSchema = z.object({
NODE_ENV: z.enum(["development", "test", "production"]),
CLERK_SECRET_KEY: z.string().optional(),
CLOUDFLARE_R2_URL: z.string().optional(),
CLOUDFLARE_SECRET_KEY: z.string().optional(),
CLOUDFLARE_KEY_ID: z.string().optional(),
CLOUDFLARE_BUCKET: z.string().optional(),
})
# apps/nextjs/src/env/schema.mjs
export const serverSchema = z.object({
NODE_ENV: z.enum(["development", "test", "production"]),
CLERK_SECRET_KEY: z.string().optional(),
CLOUDFLARE_R2_URL: z.string().optional(),
CLOUDFLARE_SECRET_KEY: z.string().optional(),
CLOUDFLARE_KEY_ID: z.string().optional(),
CLOUDFLARE_BUCKET: z.string().optional(),
})
this is what i have right now whatelse do i need to change? im so lost this works perfectly locally
julius
julius2y ago
Im not familiar with amplify but if they dont populate process.env that’s the issue you need to fix first
elpupper
elpupperOP2y ago
they do just not in SSR so the clerk and prisma stuff work fine but then the cloudflare stuff that i have in my api endpoints that use the process.env dont
elpupper
elpupperOP2y ago
Making environment variables accessible to server-side runtimes - A...
Amplify Hosting supports adding environment variables to your application's builds by setting them in the project's configuration in the Amplify console. However, a Next.js server component doesn't have access to those environment variables by default. This behavior is intentional to protect any secrets stored in environment variables that your ...
elpupper
elpupperOP2y ago
tried this out and didnt work for me
JacobMGEvans
JacobMGEvans2y ago
You can bump a question just by commenting in it. Do you HAVE to use Amplify?
elpupper
elpupperOP2y ago
no not really what else would you recommend vercel is too expensive if you are confused i got a the t3 monorepo with nextjs and expo
Neto
Neto2y ago
cloudflare
elpupper
elpupperOP2y ago
the issue isnt cloudflare i promise you
Neto
Neto2y ago
sst (for serverless)
elpupper
elpupperOP2y ago
or are u recommending services oh yeah SST i forgot about that
Neto
Neto2y ago
lmao
elpupper
elpupperOP2y ago
😭
Neto
Neto2y ago
with sst you can easily use env vars using secret manager
JacobMGEvans
JacobMGEvans2y ago
If I am confused... lmfao
elpupper
elpupperOP2y ago
im gonna link what im using right now https://github.com/clerkinc/t3-turbo-and-clerk i think the issue is the location of the .env maybe its adding it tp apps/nextjs instead of root i think ill just go ahead and use SST fucking forgot about it quick update my friend managed to fix it i have no clue how but now getting a wonderful prisma error 😄 time to solve that one
JacobMGEvans
JacobMGEvans2y ago
Try to get your friend to describe how here and mark it as an answer please.
elpupper
elpupperOP2y ago
ok So basically in the build commands he added
build:
commands:
- echo "MY_ENV=$MY_ENV" >> ../../.env
- echo "MY_ENV_1=$MY_ENV_1" >> ../../.env
- echo "MY_ENV_2=$MY_ENV_2" >> ../../.env
build:
commands:
- echo "MY_ENV=$MY_ENV" >> ../../.env
- echo "MY_ENV_1=$MY_ENV_1" >> ../../.env
- echo "MY_ENV_2=$MY_ENV_2" >> ../../.env
replace MY_ENV with ur vars then inside next.config.mjs in const config add env
env: {
MY_ENV: process.env.MY_ENV ?? "",
MY_ENV_1: process.env.MY_ENV_1 ?? "",
MY_ENV_2: process.env.MY_ENV_2 ?? "",
},
env: {
MY_ENV: process.env.MY_ENV ?? "",
MY_ENV_1: process.env.MY_ENV_1 ?? "",
MY_ENV_2: process.env.MY_ENV_2 ?? "",
},
and that pretty much it
elpupper
elpupperOP2y ago
GitHub
amplify-hosting/FAQ.md at main · aws-amplify/amplify-hosting
AWS Amplify Hosting provides a Git-based workflow for deploying and hosting fullstack serverless web applications. - amplify-hosting/FAQ.md at main · aws-amplify/amplify-hosting
Want results from more Discord servers?
Add your server