aws-sam-cli
aws-sam-cli copied to clipboard
Pretty print option for sam local invoke output
A nice-to-have would be a pretty print option that could be passed to sam local invoke.
@buildbreakdo What do you mean by pretty print? Can you give us an example to help us understand what you are looking for in the output.
@jfuss Any output coming from SAM CLI (v1.2.0) is presented on a single line. This makes working with and inspecting JSON of any consequence difficult.
It would be a nice quality-of-life fix if there were an option to format this output.
I've noticed this only applies when I updated my function's Event Source from API to HttpApi. Could be missing something still though. The header response contains the application/json content-type still. It may be because the result endpoint response is returned with single quotes.
Update: Forgot I needed to JSON.stringify
after lambda proxy integration . Works fine now! 👌
Update: Forgot I needed to
JSON.stringify
after lambda proxy integration . Works fine now! 👌
However, it doesn't seem possible to space out the output. Example JSON.stringify(object, null, 2) does not result in a human-readable output.
I've been able to get a pretty print output by combining tail and jq using the following command. This only works when you return a json object as a response from the function.
sam invoke local searchFunction | tail -1 | jq
I can then use jq filters to view the information I need from the responses while developing locally.
Closing this issue as piping the output to jq gives you the same results.