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
elpupper12mo 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
julius12mo ago
Im not familiar with amplify but if they dont populate process.env that’s the issue you need to fix first
elpupper
elpupper12mo 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
elpupper12mo 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
elpupper12mo ago
tried this out and didnt work for me
JacobMGEvans
JacobMGEvans12mo ago
You can bump a question just by commenting in it. Do you HAVE to use Amplify?
elpupper
elpupper12mo 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
Neto12mo ago
cloudflare
elpupper
elpupper12mo ago
the issue isnt cloudflare i promise you
Neto
Neto12mo ago
sst (for serverless)
elpupper
elpupper12mo ago
or are u recommending services oh yeah SST i forgot about that
Neto
Neto12mo ago
lmao
elpupper
elpupper12mo ago
😭
Neto
Neto12mo ago
with sst you can easily use env vars using secret manager
JacobMGEvans
JacobMGEvans12mo ago
If I am confused... lmfao
elpupper
elpupper12mo 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
JacobMGEvans12mo ago
Try to get your friend to describe how here and mark it as an answer please.
elpupper
elpupper12mo 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
elpupper11mo 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
More Posts
Making a enum/union type like in prisma, but with drizzleI have this a role `pgEnum` and I want to make a enum type that is also a union type, like what happT3 ESLint Not Following Next.js Official ESLint DocsT3: https://github.com/t3-oss/create-t3-app/blob/55fd7711a1376de8dbf22aff43af6acb8dcbafd2/cli/templaproblem importing first npm packageI’m trying to import my first npm package and getting a “cannot find module” error, funnily, with itwhere should these variables be in my env var configurationguys, where should these variables be in my env var configuration? the documentation isn't very cleaRefactor typeI got a type def - ```js // Clear this mess type GeneralCondition<T extends ValidSubscription> = { "no-cache" | revalidate: 0 breaks site in productionAs title say, "no-cache" and "revalidate: 0" breaks site in production, on local it works fine. AlsoProblem with adding per-page layout in /pages router using typescript``` // eslint-disable-next-line @typescript-eslint/ban-types export type NextPageWithLayout<P = {}, drizzle studio is not workingI am trying to open drizzle studio but it is giving me error can anyone tell my how to fix it? drizHas anyone used UploadThing to self-host file uploads in a CMS?I wonder if anyone uses `UploadThing` as their file upload storage for an open-source headless CMS sperforming server-side authentication with t3-app stack before rendering the index pageMy root `pages/index.tsx` page is functioning as expected: a `useSession()` call is made to see if t