1

I'm making a call to the AWS Lambda CLI to invoke my function. I want to get the function response (Payload) as part of my return object so I'm passing --invocation-type RequestResponse. With that, I'm still only getting the function output in my output file (which I actually don't care about). I want it as part of the object returned from this CLI call but there I only get the LogResult and the StatusCode.

{
    "LogResult": "encoded blah blah blah", 
    "StatusCode": 200
}

Am I making a typo in my command or am I missing something? How can I get the function output (Payload) as part of the object returned from this CLI call?

aws lambda invoke --function-name myFunction --invocation-type RequestResponse --log-type Tail --payload {} --region us-east-1 testoutput.txt
Brady Dowling
  • 3,296
  • 2
  • 22
  • 43
  • Please verify you have the latest version of the AWS CLI tool with the command `aws --version` – Mark B Nov 04 '17 at 22:02
  • Running version 1.11.129, which is of course outdated, but when I try to upgrade with `pip install awscli --upgrade --user` I have that same version. Not sure how to get up to 1.11.84 (I'm on Amazon Linux). – Brady Dowling Nov 04 '17 at 22:46
  • 1.11.129 is a neweer version than 1.11.84. 129 is greater than 84 – Mark B Nov 04 '17 at 23:04
  • good point. Good ole semantic versioning ;) So I'm back to square one, not sure what's causing this. – Brady Dowling Nov 04 '17 at 23:09

1 Answers1

3

I want to get the function response (Payload) as part of my return object so I'm passing --invocation-type RequestResponse

That isn't what that option does. Also, specifying this is essentially a no-op, since RequestResponse is already the default. The alternative (Event) tells Lambda to run the function asynchronously (from your perspective) without waiting for it to complete. It's not about how the response is collected or returned, but rather whether the response is completely discarded because your invocation request is detached from the running function and returns immediately.

I'm still only getting the function output in my output file

That's exactly how it is supposed to work. That's why you have to specify an output file. The function output is written to that file, only.

Michael - sqlbot
  • 139,456
  • 21
  • 252
  • 328
  • Ah yep, you're right about the first part. But I do need to specify this to get the logs correctly. From the docs: `You can set this optional parameter to Tail in the request only if you specify the invocation-type parameter with value RequestResponse`. And I hope you're wrong on this one: `The function output is written to that file, only.` Unfortunately, there's no indication in the docs that this is the case. The way they're written and structured, it certainly appears like it will be part of the return object but your conclusion is reasonable from the results I'm getting, thanks! – Brady Dowling Nov 05 '17 at 16:39
  • 1
    *"There's no indication in the docs that this is the case."* It's not clear why you believe... oh. Yes, I see it, now... at the bottom of the page it shows `Payload`. I had not noticed that before, since `output-file` is not an optional argument, I use that. This seems like either a documentation error or an oversight, like maybe there's a magic value you can supply for `output-file`. If all else fails, read the source. The underlying Lambda API actually supplies those other values not as JSON but as HTTP response headers, so the JSON you *do* get is actually being crafted by aws-cli. – Michael - sqlbot Nov 05 '17 at 16:53