0

I'm deploying a nextjs app router project on AWS Amplify, not my personall preference but the client wants it on AWS When deploying, I found that the Amplify enforces minimal edge runtime on all of my APIs, even the callback, hooks, where I explicitly designated the runtime as nodejs

export const runtime = 'nodejs'

and this minimal edge runtime doesn't have access to my server env vars like webhook secret, database credentials ...etc, which makes them severely limited in usage now, unless the secrets are exposed using NEXT_PUBLIC, as weirdly mentioned by Amplify docs

Tried putting the secrets in an AWS secret manager, but still need at least the secrets id as a secure env var accessible to the edge runtime APIs to use them

This is very frustrating and a strangle limitation to Nextjs projects on Amplify, does anyone have a solution for it?

I already moved some of the APIs to server actions as a workaround, but still need webhooks and callbacks for auth and payment integrations

1
  • Yeah! The Amplify cant chnage the varibles on runtime. I think the better approch is to try to pass them during the docker build itself. That is what i used to do. Commented Oct 13 at 9:43

1 Answer 1

0

I actually found the way to expose the envs to both the edge runtime APIs and the server action/pages

You need to define each env added in the amplify enviroment variables to the next.config.ts, in the envs key

const nextConfig = {
 env: { secret1:    process.env.secret1, secret2: process.env.secret2 } 
}

And make sure to use the exact name for the secret like what you defined in the next.config.ts file

Now, the secrets are read in all edge APIs and server actions

I don't know why this isn't in Amplify's docs for Next.js, but it's a real hindering factor, and I'd go for any other host if I had the preference

I hope this helps someone who gets stuck in the same issue

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.