1

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.

halfer
  • 19,824
  • 17
  • 99
  • 186
av0000
  • 1,917
  • 6
  • 31
  • 51
  • Note that we prefer a technical style of writing here. We gently discourage greetings, hope-you-can-helps, thanks, advance thanks, notes of appreciation, regards, kind regards, signatures, please-can-you-helps, chatty material and abbreviated txtspk, pleading, how long you've been stuck, voting advice, meta commentary, etc. Just explain your problem, and show what you've tried, what you expected, and what actually happened. – halfer Jun 13 '23 at 11:32

0 Answers0