amplify-hosting icon indicating copy to clipboard operation
amplify-hosting copied to clipboard

PR Preview env can't be created with env variables

Open vojtech-simko opened this issue 3 years ago • 4 comments

Before opening, please confirm:

App Id

d3pwsdrqmxpguf

Region

eu-west-2

Amplify Hosting feature

Backend builds, Environment variables

Describe the bug

I'm using the amplifyPush --simple command to build/create my backend env for Preview environments.

The build fails because of env variables and --yes flag - known issue

CREATE_FAILED functiongetOpenViduToken AWS::CloudFormation::Stack Tue Apr 19 2022 09:25:45 GMT+0000 (Coordinated Universal Time) Parameters: [openviduUrl] must have values

However, according to documentation to fix the issue you have to checkout the env and push it manually from local machine.

  1. I copy the command from Amplify console amplify pull --appId d3pwsdrqmxpguf --envName prcjb
  2. an empty env is pulled from cloud
  3. I can't update the function nor push it back to cloud (because there're no categories)

Expected behavior

I'd be great if the amplifyPush --simple (amplify push -y) command did carry over the env variables and secrets from target or current env without prompting).

Also I don't know why the failing env is empty why I pull it. Without it there's no way how to fix the env variables.

Reproduction steps

  1. Create lambda function that uses some env variable.
  2. Define value for current environment and push to cloud - check if value is included in team-provider-info.json
  3. Setup PR Previews for current branch in Amplify Console - Create new backend environment for every Pull Request
  4. Create new branch from current branch
  5. Make some changes, add dummy file etc.
  6. Push changes to remote and create PR for the new branch.
  7. PR env build should fail - try to pull the env from cloud.

Build Settings

version: 1
backend:
    phases:
        build:
            commands:
                - amplifyPush -e "${AWS_BRANCH}" --simple
frontend:
    phases:
        preBuild:
            commands:
                - npm ci
        build:
            commands:
                - npm run build-prod
    artifacts:
        baseDirectory: dist/stardio-pro
        files:
            - "**/*"
    cache:
        paths:
            - node_modules/**/*

Additional information

No response

vojtech-simko avatar Apr 19 '22 10:04 vojtech-simko

I'd also be good if the parameter -e "${AWS_BRANCH}" was actually respected and used for the new env name. Right now there's USER_BRANCH variable for each PR env that's overriding the -e input. I know amplify env name has a strict naming conditions (no dashes, no uppercase, 10 chars) but that can be stripped out from the input. I'd make more sense to have the envs named after git branches or PR numbers.

vojtech-simko avatar Apr 19 '22 10:04 vojtech-simko

Hi @vojtech-simko 👋🏽 thanks for providing details and reproduction steps. We're taking a look into this issue.

ghost avatar Apr 19 '22 14:04 ghost

any update on this ??

Oluwasetemi avatar Aug 03 '22 13:08 Oluwasetemi

I guess that for now as soon we have environment variables or secrets on lambda functions the preview won't work? 😢 It would be great to understand if this is something the AWS team has ideas on how to fix it, although seems like a pretty heavy lift

duranmla avatar Aug 03 '22 14:08 duranmla