aws-sam-cli icon indicating copy to clipboard operation
aws-sam-cli copied to clipboard

Pretty print option for sam local invoke output

Open buildbreakdo opened this issue 6 years ago • 5 comments

A nice-to-have would be a pretty print option that could be passed to sam local invoke.

buildbreakdo avatar Mar 13 '18 18:03 buildbreakdo

@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 avatar Oct 13 '20 16:10 jfuss

@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.

seanlindo avatar Nov 11 '20 06:11 seanlindo

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.

tdreid92 avatar Jan 18 '21 13:01 tdreid92

Update: Forgot I needed to JSON.stringify after lambda proxy integration . Works fine now! 👌

tdreid92 avatar Jan 18 '21 14:01 tdreid92

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.

AndrewZelaya avatar Feb 05 '21 21:02 AndrewZelaya

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.

julianpitt avatar Sep 12 '22 04:09 julianpitt

Closing this issue as piping the output to jq gives you the same results.

sriram-mv avatar Sep 19 '22 20:09 sriram-mv