serverless / serverless

⚡ Serverless Framework – Effortlessly build apps that auto-scale, incur zero costs when idle, and require minimal maintenance using AWS Lambda and other managed cloud services.
https://serverless.com
MIT License
46.47k stars 5.72k forks source link

load env variables from .env files failed #10763

Closed Jadenhub closed 2 years ago

Jadenhub commented 2 years ago

Are you certain it's a bug?

Are you using the latest version?

Issue description

I run npx serverless offline --apiKey just_key --prefix dev, but get error.

Package.json

    "serverless-dotenv-plugin": "^2.4.2",
    "serverless-offline": "^5.12.1",
    "serverless-pseudo-parameters": "^2.4.0"

Service configuration (serverless.yml) content

provider:
  name: aws
  stage: ${env:AWS_STAGE}
  memorySize: 256
  runtime: nodejs12.x
  role: LambdaRole
  environment:
    STAGE: ${self:custom.STAGE}
    #postgresql
    POSTGRES_DB: ${env:POSTGRES_DB}
    POSTGRES_HOST: ${env:POSTGRESQL.HOST}
    POSTGRES_PORT: ${env:POSTGRESQL.PORT}
    POSTGRES_USER: ${env:POSTGRES_USER}
    POSTGRES_PASSWORD: ${env:POSTGRES_PASSWORD}
custom:
  STAGE: ${opt:stage, self:provider.stage}
  BASE_URL_V1: /api/v1
  POSTGRES_DB: catcrouch_db
  POSTGRESQL:
  #   HOST:
  #     Fn::GetAtt: [PostgreSqlRDSInstance, Endpoint.Address]
  #   PORT:
  #     Fn::GetAtt: [PostgreSqlRDSInstance, Endpoint.Port]
    VPC_CIDR: 10
  POSTGRES_USER: ${env:POSTGRES_USER}
  POSTGRES_PASSWORD: ${env:POSTGRES_PASSWORD}
  serverless-offline:
    noAuth: true
    stages: dev

plugins:
  - serverless-dotenv-plugin
  - serverless-pseudo-parameters
  - serverless-offline

Command name and used flags

npx serverless offline --apiKey just_key --prefix dev

Command output

npx serverless offline --apiKey just_key --prefix dev
Environment: darwin, node 12.18.2, framework 3.4.0, plugin 6.1.2, SDK 4.3.1
Docs:        docs.serverless.com
Support:     forum.serverless.com
Bugs:        github.com/serverless/serverless/issues

Error:
Cannot resolve serverless.yml: Variables resolution errored with:
  - Cannot resolve variable at "provider.stage": Value not found at "env" source

Environment information

Framework Core: 3.4.0
Plugin: 6.1.2
SDK: 4.3.1
pgrzesik commented 2 years ago

Hello @Jadenhub - this looks like an issue with offline and/or the `serverless-dotenv-plugin - did you check how it was impacted with v3 Framework release?

I'm going to close this one as it seems to be related directly to the plugin - if you feel like there's a bug, please open a ticket in corresponding plugin's repository.