aws-amplify / aws-amplify/amplify-hosting

Environment variables' overwrites are ignored

Open
#3,134 4 comments 1 reaction 0 assignees View on GitHub
compute question
Dominant language
Dockerfile
Stars
481
Forks
123
PR merge metrics
No merged PRs in 30d

Description

### Before opening, please confirm:

- [X] I have checked to see if my question is addressed in the [FAQ](https://github.com/aws-amplify/amplify-hosting/blob/master/FAQ.md).
- [X] I have [searched for duplicate or closed issues](https://github.com/aws-amplify/amplify-hosting/issues?q=is%3Aissue+).
- [X] I have read the guide for [submitting bug reports](https://github.com/aws-amplify/amplify-hosting/blob/master/CONTRIBUTING.md).
- [X] I have done my best to include a minimal, self-contained set of instructions for consistently reproducing the issue.
- [X] I have removed any sensitive information from my code snippets and submission.

### App Id

dyc40is5dgmni

### AWS Region

eu-central-1

### Amplify Hosting feature

Environment variables

### Describe the bug

I have recently migrated my NextJS Amplify application to Web Compute. I encountered the same problem with cloudfront as here: https://github.com/aws-amplify/amplify-hosting/issues/3125 which I was able to resolve by re-editing the "Rewrites and Redirects" and setting Source address /<*> to Target a cloudfront distribution from before the migration.

Today, when deploying code to our staging website for the first time since migrating I saw that the environment variables' overwrites are ignored. Which results in our staging website trying to communicate with production endpoints.

When adding `echo $SOME_VARIABLE` into `amplify.yml` I see the correct environment variable is available, but when deployment is done then production ones are used in the deployed code.

### Expected behavior

I expect the correct environment variables to be applied when application is deployed using our staging branch

### Reproduction steps

1. Set a variable overwrite for staging for backend url
2. (Re)Deploy code
3. Observe on the staging website that incorrect environment variable is used

### Build Settings

```yaml
version: 1
frontend:
phases:
preBuild:
commands:
- npm ci
build:
commands:
- npm run build
artifacts:
baseDirectory: .next
files:
- '**/*'
cache:
paths:
```
```

### Log output

_No response_

### Additional information

_No response_

Contributor guide

Open the contributing guide

Research direction

Start with the reported amplify.yml build settings and the staging-branch deployment flow, using the three reproduction steps to compare the overwritten variable with the value used by the deployed NextJS application. Done means staging consistently uses its configured environment-variable overwrite rather than the production value after deployment.

Written by the indexing model from the issue text.

Assessment

Tech stack
aws, nextjs
Domain
ci-cd, cloud
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.