Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Environment Variable Not Injected Into Application Function #2190

Open
Leectan opened this issue Nov 3, 2024 · 2 comments
Open

Environment Variable Not Injected Into Application Function #2190

Leectan opened this issue Nov 3, 2024 · 2 comments
Labels
hosting Issue related to Amplify Hosting pending-response Issue is pending response from author question Question or confusion about some aspect of the product

Comments

@Leectan
Copy link

Leectan commented Nov 3, 2024

Environment information

System:
  OS: macOS 15.0.1
  CPU: (10) arm64 Apple M1 Max
  Memory: 164.13 MB / 64.00 GB
  Shell: /bin/zsh
Binaries:
  Node: 21.7.3 - /opt/homebrew/bin/node
  Yarn: 1.22.22 - /opt/homebrew/bin/yarn
  npm: 10.5.0 - /opt/homebrew/bin/npm
  pnpm: 9.12.3 - /opt/homebrew/bin/pnpm
NPM Packages:
  @aws-amplify/auth-construct: 1.4.0
  @aws-amplify/backend: 1.6.0
  @aws-amplify/backend-auth: 1.3.0
  @aws-amplify/backend-cli: 1.4.0
  @aws-amplify/backend-data: 1.1.6
  @aws-amplify/backend-deployer: 1.1.6
  @aws-amplify/backend-function: 1.7.3
  @aws-amplify/backend-output-schemas: 1.4.0
  @aws-amplify/backend-output-storage: 1.1.3
  @aws-amplify/backend-secret: 1.1.4
  @aws-amplify/backend-storage: 1.2.2
  @aws-amplify/cli-core: 1.2.0
  @aws-amplify/client-config: 1.5.1
  @aws-amplify/deployed-backend-client: 1.4.2
  @aws-amplify/form-generator: 1.0.3
  @aws-amplify/model-generator: 1.0.8
  @aws-amplify/platform-core: 1.1.0
  @aws-amplify/plugin-types: 1.3.1
  @aws-amplify/sandbox: 1.2.4
  @aws-amplify/schema-generator: 1.2.5
  aws-amplify: 6.8.0
  aws-cdk: 2.165.0
  aws-cdk-lib: 2.165.0
  typescript: 5.6.3
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
!!                                                                            !!
!!  Node 21 has reached end-of-life on 2024-06-01 and is not supported.       !!
!!  Please upgrade to a supported node version as soon as possible.           !!
!!                                                                            !!
!!  This software is currently running on node v21.7.3.                       !!
!!  As of the current release of this software, supported node releases are:  !!
!!  - ^22.0.0 (Planned end-of-life: 2027-04-30)                               !!
!!  - ^20.0.0 (Planned end-of-life: 2026-04-30)                               !!
!!  - ^18.0.0 (Planned end-of-life: 2025-04-30)                               !!
!!                                                                            !!
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
AWS environment variables:
  AWS_STS_REGIONAL_ENDPOINTS = regional
  AWS_NODEJS_CONNECTION_REUSE_ENABLED = 1
  AWS_SDK_LOAD_CONFIG = 1
No CDK environment variables

Describe the bug

AWS Amplify by default do not inject environment variables into serverless function, even though environment variable have been explicitly specified, in contrast compared to vercel. This leads to application error and challenging to debug. Environment variable has to also be explicitly specified in amplify.yml build file to bypass this bug.

proof4
proof3
proof1

Reproduction steps

Step1: process.env.ENV is called in code.
Step2: Specify environment variable in amplify.
Step3: Application failed and log shows no environment specified.

@Leectan Leectan added the pending-triage Incoming issues that need categorization label Nov 3, 2024
@Leectan
Copy link
Author

Leectan commented Nov 3, 2024

Vercel doesn't have this bug FYI.

@ykethan ykethan added the hosting Issue related to Amplify Hosting label Nov 4, 2024
@Jay2113 Jay2113 added question Question or confusion about some aspect of the product and removed pending-triage Incoming issues that need categorization labels Nov 4, 2024
@Jay2113
Copy link

Jay2113 commented Nov 4, 2024

Hi @Leectan 👋 , thanks for reaching out. You can make the environment variables accessible to the Next.js compute runtime by adding them in an environment file .env.production that the framework recognizes. You will need to modify the Amplify build specification file amplify.yml as follows:

version: 1
frontend:
  phases:
    preBuild:
      commands:
        - npm ci
    build:
      commands:
        - env | grep -e EMAIL -e HOST -e PASS -e PORT >> .env.production
        - npm run build
  artifacts:
    baseDirectory: .next
    files:
      - '**/*'
  cache:
    paths:
      - node_modules/**/*
      - .next/cache/**/*

Docs: https://docs.aws.amazon.com/amplify/latest/userguide/ssr-environment-variables.html

@Jay2113 Jay2113 added the pending-response Issue is pending response from author label Nov 4, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
hosting Issue related to Amplify Hosting pending-response Issue is pending response from author question Question or confusion about some aspect of the product
Projects
None yet
Development

No branches or pull requests

3 participants