Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Invoking aws lambda without output file

I'm trying to invoke a lambda on AWS using CLI:

aws lambda invoke --function-name GetErrorLambda --payload '{"body":"{\"Id\":[\"321\",\"123\"]}"}' \output. 

I would like to know if there's a way to print the output on the cli instead of create a file.

Thanks in advance.

like image 668
BernardoMorais Avatar asked Dec 06 '17 13:12

BernardoMorais


People also ask

How do you invoke lambda with input?

To invoke a lambda function synchronously, use the invoke command, passing it the function name, the payload and the output filename as parameters. Copied! If you're on Windows , escape the double quotes of the --payload parameter, e.g. '{\"name\": \"John Smith\"}' .


2 Answers

stdout and stderr are basically files so can be used for arguments that expect one

aws lambda invoke --function-name GetErrorLambda --payload '{"body":"{\"Id\":[\"321\",\"123\"]}"}' /dev/stdout 

though in this case the rest of the commands output will overlap with it, so probably better to cat it later anyways

like image 154
Vlad Avatar answered Sep 18 '22 16:09

Vlad


It's not possible to output directly to the terminal after invoking a lambda function. This is likely by design as the output could easily be greater than the buffer size for a window.

A simple workaround would be to simply 'cat' out the contents of the output file following the cli command like so:

aws lambda invoke --function-name GetErrorLambda --payload '{"body":"{\"Id\":[\"321\",\"123\"]}"}' \output. && cat outputFileName.txt

like image 23
Adam Thomason Avatar answered Sep 18 '22 16:09

Adam Thomason