I'm following these docs on Environment Secrets and am trying to access my secret in a build command to provide an api key for my Next.js app.
The docs say:
Accessing an environment secret during a build is similar to accessing environment variables, except that environment secrets are stored in process.env.secrets as a JSON string.
My parameter store has a secret at /amplify/{my-app-id-here}/dev/API_KEY
In local, when I can just use .env.local everything works fine, but when I try my "live" site I get:
{"error":{"message":"API key not configured"}}
Relevant Build Commands:
phases:
preBuild:
commands:
- npm ci
- echo $SECRETS | grep -o '"API_KEY":"[^"]*' | sed 's/"API_KEY":"//g' > .env.local
I have tried $SECRETS
, $PROCESS_ENV_SECRETS
, ${process.env.secrets}
, etc. but I keep getting the error. I think I am not properly accessing process.env.secrets
but I am not sure.
I even tried just returning "process.env" and did not see the key there.