Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Change command output format to JSON #592

Open
OranShuster opened this issue Oct 12, 2023 · 1 comment
Open

Change command output format to JSON #592

OranShuster opened this issue Oct 12, 2023 · 1 comment

Comments

@OranShuster
Copy link

OranShuster commented Oct 12, 2023

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

  • Serverless Framework Core Version you're using:3.35.2
  • The Plugin Version you're using:3.15.0
  • Operating System:node:18 (based on debian bookworm)
  • Stack Trace: N/A
  • Provider Error messages: N/A
@OranShuster
Copy link
Author

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant