Skip to content

invoke local does not work with variable substitution in provider #4817

@Omicron7

Description

@Omicron7

This is a Bug Report

Description

When running sls invoke local with variable substitution ${} in the provider configuration, nothing happens and the command exits.

I expected the invoked function to be executed, or if the function could not be found, an error message describing that the function does not exist in this service.

Example using the hello-world template. (serverless create --template hello-world).

service: serverless-hello-world
provider:
  name: aws
  runtime: nodejs6.10
functions:
  helloWorld:
    handler: handler.helloWorld
    events:
      - http:
          path: hello-world
          method: get
          cors: true

Invoke local functions properly:

bash> serverless invoke local --function helloWorld
{
    "statusCode": 200,
    "headers": {
        "Access-Control-Allow-Origin": "*"
    },
    "body": "{\"message\":\"Go Serverless v1.0! Your function executed successfully!\",\"input\":\"\"}"
}

Changing serverless.yml to include variable substitution in the provider:

service: serverless-hello-world
custom:
  provider:
    name: aws
    runtime: nodejs6.10
# The `provider` block is referenced from custom using variable substitution
provider: ${self:custom.provider}
functions:
  helloWorld:
    handler: handler.helloWorld
    events:
      - http:
          path: hello-world
          method: get
          cors: true

results in invoke local doing nothing.

bash> serverless invoke local --function helloWorld

It produces no output or error. Running with SLS_DEBUG=* enabled shows that commands are loaded, invoke:local is executed, but nothing happens. Providing an unknown function name results in the same response, no message or error.

This is just an example that produces the results I'm running into. I'm using similar to change the provider configuration depending on wether serverless is being run in development or on our CI server.

  • Serverless Framework Version you're using: 1.26.1
  • Operating System: OSX 10.13.3, node v9.3.0, npm 3.10.10
  • Stack Trace:
  • Provider Error messages:

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