Skip to content

V4: .env variables do not work in serverles.yml #12628

@gsavvidis96

Description

@gsavvidis96

Issue description

In serverless v3, this serverless.yml file successfully deploys:

service: test
frameworkVersion: "3"
useDotenv: true

provider:
  name: aws
  runtime: nodejs20.x
  region: eu-south-1
  profile: ${env:AWS_PROFILE}
  deploymentMethod: direct
  httpApi:
    cors: true

functions:
  custom:
    handler: handler.handler

While in serverless v4 with the equivalent serverless.yml configuration I get an error:

service: test

provider:
  name: aws
  runtime: nodejs20.x
  region: eu-south-1
  profile: ${env:AWS_PROFILE}
  deploymentMethod: direct
  httpApi:
    cors: true

functions:
  custom:
    handler: handler.handler

As per docs, environment variables from a .env file should load by default.

If I replace ${env:AWS_PROFILE} with a hardcoded profile, it works fine.

Context

Summary Report -----------------

Service Overview

  • Serverless Framework Version: 4.1.5
  • Service Config File: serverless.yml
  • Service Name: test
  • Service Runtime: nodejs20.x
  • Service Region: eu-south-1
  • Command: deploy
  • Error Code: AWS_CREDENTIALS_MISSING

Service Path

C:\Users\sav\Desktop\gym-appointments-api

Error Message

AWS credentials missing or invalid. Run "serverless" to set up AWS credentials, or learn more in our docs: http://slss.io/aws-creds-setup. Original error from AWS: Could not load credentials from any providers

Service Config

service: test
provider:
  runtime: nodejs20.x
  region: eu-south-1
  profile: ${env:AWS_PROFILE}
  deploymentMethod: direct
  httpApi:
    cors: true
functions:
  custom:
    handler: handler.handler

Metadata

Metadata

Assignees

Labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions