In AWS Amplify, open your app and navigate to the Build Settings section from the left-hand sidebar. Locate the amplify.yml file and manually update it to include your environment variables in the following format:
amplify.yml
should look like something similar
version: 1
frontend:
phases:
preBuild:
commands:
- npm ci --cache .npm --prefer-offline
build:
commands:
- npm run build
artifacts:
baseDirectory: .next
files:
- '**/*'
cache:
paths:
- .next/cache/**/*
- .npm/**/*
env:
variables:
# Env
NODE_ENV: "production"
NAME_OF_VARIABLE_YOU_USE_ON_NEXT: ${NAME_OF_VARIABLE_YOU_SAVED_ON_AMPLIFY}
In your use case you would do something like this:
env:
variables:
# Env
API_KEY: ${API_KEY}[![enter image description here][1]][1]
and then in your next application:
your_api_key = process.env.API_KEY