serverless
serverless copied to clipboard
Allow raw output from `sls invoke` without JSON encoding
Is there an existing issue for this?
- [X] I have searched existing issues, it hasn't been reported yet
Use case description
It would be useful to be able to able to get the raw output from the invoke command, similar to how the --raw switch works for input. The invoke and the invoke local commands stringify the output.
At the moment to generate a CSV file the output must be unstringified:
sls invoke local -f export --data XXX | node -e 'console.log(JSON.parse(fs.readFileSync("/dev/stdin", "utf-8")));' > out.csv
Proposed solution (optional)
Adding a --rawOutput command switch.
Actually, because Serverless uses STDERR for its own output, the only way to differentiate errors from normal output is to try and parse the JSON:
OUTPUT=$(sls invoke local -f export --data XXX)
if CSV=$(echo $OUTPUT | node -e 'console.log(JSON.parse(fs.readFileSync("/dev/stdin", "utf-8")));' 2>&1); then
echo "$CSV"
else
echo "$OUTPUT"
fi