Skip to content

${self:service} and ${self:service.name} are not available in serverless.yml in 1.36.3 #5759

Closed

Description

@aaleksandrov

This is a Bug Report

Description

  • ${self:service} and ${self:service.name} are not available in serverless.yml in 1.36.3 , in 1.34 it was working as expected
    My serverless.yml
service:
  name: rps-project
provider:
  stage: ${opt:stage, self:custom.env.stage}
  environment:
    NEW_RELIC_APP_NAME: "${self:service}-${self:provider.stage}"

yarn serverless print

service:
  name: rps-project
provider:
  stage: alexandrov
  environment:
    NEW_RELIC_APP_NAME: '-alexandrov'

After downgrading to 1.34 output is correct:

service:
  name: rps-project
provider:
  stage: alexandrov
  environment:
    NEW_RELIC_APP_NAME: 'rps-project-alexandrov'

Similar or dependent issues:

Additional Data

  • 1.36.3
  • Ubuntu 16.04

Activity

  1. dschep commented on Jan 28, 2019

    @dschep
    Contributor

    Hmm. I wasn't able to replicate the issue. Is the problem recreated for you when you try my test repo? https://github.com/dschep-bug-repos/sls-5759

    
    $ sls version
    1.36.3
    $ grep -v -e '^\s*$' -e '^\s*#' serverless.yml
    service:
      name: sls-5759
    provider:
      name: aws
      runtime: nodejs8.10
      environment:
        SERVICE: ${self:service.name}
        STAGE: ${opt:stage, self:provider.stage}
    functions:
      hello:
        handler: handler.hello
    $ sls print
    service:
      name: sls-5759
    provider:
      name: aws
      runtime: nodejs8.10
      environment:
        SERVICE: sls-5759
        STAGE: dev
    functions:
      hello:
        handler: handler.hello
    
  2. aaleksandrov commented on Jan 29, 2019

    @aaleksandrov
    Author

    @dschep Your example works fine for me.
    Sorry, I missed one detail in my setup because I supposed it was irrelevant. This is my extended serverless.yml , as you see service.name contains variable as well.

    service:
      name: rps-project${self:custom.env.rpsRegion, ""}
    provider:
      stage: ${opt:stage, self:custom.env.stage}
      environment:
        NEW_RELIC_APP_NAME: "${self:service}-${self:provider.stage}"
    custom:
      env: ${file(${opt:environment, self:custom.defaultEnv})}
      defaultEnv: "./environments/local.yml"
    

    /environments/local.yml:

    rpsRegion: ""
    

    For 1.34 and older version this setup works well

  3. dschep commented on Jan 29, 2019

    @dschep
    Contributor

    Aha. Thanks, I've now recreated the issue. The problem seems to be with when the fallback variable is used in the service name, it's losing the string literal portions:

    $ sls version
    1.36.3
    $ grep -v -e '^\s*$' -e '^\s*#' serverless.yml
    service:
      name: sls-5759-${self:custom.foo, "wat"}
    provider:
      name: aws
      runtime: nodejs8.10
      environment:
        SERVICE: ${self:service.name}
        STAGE: ${opt:stage, self:provider.stage}
    functions:
      hello:
        handler: handler.hello
    $ sls print
    service:
      name: sls-5759-wat
    provider:
      name: aws
      runtime: nodejs8.10
      environment:
        SERVICE: wat
        STAGE: dev
    functions:
      hello:
        handler: handler.hello
    
  4. dschep commented on Jan 30, 2019

    @dschep
    Contributor

    Hey @aaleksandrov, for the time being, here's a workaround:

    $ grep -v -e '^\s*$' -e '^\s*#' serverless.yml
    custom:
      default: ''
    service:
      name: sls-5759-${self:custom.foo, self:custom.default}
    provider:
      name: aws
      runtime: nodejs8.10
      environment:
        SERVICE: ${self:service.name}
        STAGE: ${opt:stage, self:provider.stage}
    functions:
      hello:
        handler: handler.hello
    $ sls print
    custom:
      default: ''
    service:
      name: sls-5759-
    provider:
      name: aws
      runtime: nodejs8.10
      environment:
        SERVICE: sls-5759-
        STAGE: dev
    functions:
      hello:
        handler: handler.hello
    
  5. medikoo commented on Mar 3, 2021

    @medikoo
    Contributor

    Fixed with #8987

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions