serverless-heaven / serverless-aws-alias

Alias support for Serverless 1.x
MIT License
189 stars 68 forks source link

Serverless logs does not work with alias plugin #38

Closed HyperBrain closed 7 years ago

HyperBrain commented 7 years ago

Invoking serverless logs leads to error message.

$ node node_modules/serverless/bin/serverless logs --stage=dev --function=authen               ticate

  Serverless Error ---------------------------------------

     1 validation error detected: Value '[]' at 'logStreamNames'
     failed to satisfy constraint: Member must have length
     greater than or equal to 1

  Get Support --------------------------------------------
     Docs:          docs.serverless.com
     Bugs:          github.com/serverless/serverless/issues
     Forums:        forum.serverless.com
     Chat:          gitter.im/serverless/serverless

  Your Environment Information -----------------------------
     OS:                 win32
     Node Version:       6.10.1
     Serverless Version: 1.12.1

Additionally to this defect, the alias plugin should add support for the --alias option to show the log from an aliased function.

HyperBrain commented 7 years ago

Investigated the issue. The problem is, that SLS logs filters all log streams that have $LATEST in their name:

        return _.chain(reply.logStreams)
          .filter(stream => stream.logStreamName.includes('[$LATEST]'))
          .map('logStreamName')
          .value();

Naturally, deployed aliases would never occur as $LATEST but with the actually deployed version.

So the correct fix would be that the alias plugin checks the current version for any alias and just emits the logs for the selected alias.