serverless-operations / serverless-step-functions

AWS Step Functions plugin for Serverless Framework ⚡️
Other
1.03k stars 203 forks source link

Change command output format to JSON #592

Open OranShuster opened 11 months ago

OranShuster commented 11 months ago

This is a Feature Proposal

Description

We have a use case where we call serverless framework from a language other than JS. for serverless invoke stepf... the output is a javascript object string (properties are not quoted)

{
  executionArn: '...',
  stateMachineArn: '...',
  ...
}

This means that regular JSON parsers will break and you will need some JS interpreter in the middle to get a proper JSON out of this

i propose a new optional flag for all commands --jsonOutput/--output json that will tell the command that it needs to run its result through JSON.stringify before printing it to stdout/stderr

Additional Data

OranShuster commented 11 months ago

While looking into this i found another issue related to logging in invoke in the serverless framework docs for plugin development it says

Best practices:

* stdout output is usually meant to be piped to/parsed by another program.
* Plugins should only write to stdout in commands they define (to avoid breaking the output of other commands).
* The only content written to stdout should be the main output of the command.

Take, for example, the serverless invoke command:

*Its output is the result of the Lambda invocation: by writing that result (and only that) to stdout, it allows any script to parse the result of the Lambda invocation.
*All other messages should be written to stderr: such logs are useful to humans, for example configuration warnings, upgrade notifications, Lambda logs… Since they are written to stderr, they do not break the parsable output of stdout.

invoke stepf uses the .log method and not the writeText(). this means that even if we decided to go with piping the output to another process we would need to filter out the rest of stderr output