Reputation: 2976
I have created a function "gen_MC_calculate_compound". When I call aws lambda list-functions I get:
{
"Functions": [
{
"FunctionName": "gen_MC_calculate_compound",
...
}
}
At the moment it is the hello world example:
#include <aws/lambda-runtime/runtime.h>
using namespace aws::lambda_runtime;
invocation_response my_handler(invocation_request const& request)
{
return invocation_response::success("Hello, World!", "application/json");
}
int main()
{
run_handler(my_handler);
return 0;
}
I can invoke it from the command line with:
aws lambda invoke --function-name gen_MC_calculate_compound out.txt
and I get a successful result:
{
"StatusCode": 200,
"ExecutedVersion": "$LATEST"
}
I have in the following code to invoke using C++ SDK:
Aws::Lambda::Model::InvokeRequest invokeRequest;
invokeRequest.SetFunctionName("gen_MC_calculate_compound");
// RequestResponse == synchronous
invokeRequest.SetInvocationType(
Aws::Lambda::Model::InvocationType::RequestResponse);
// Tail == logging on
invokeRequest.SetLogType(Aws::Lambda::Model::LogType::Tail);
{
auto const payload_json = to_json(args);
auto const payload_ss = std::make_shared<Aws::StringStream>();
*payload_ss << payload_json.View().WriteReadable();
invokeRequest.SetBody(payload_ss);
invokeRequest.SetContentType("application/javascript");
}
std::cerr << "invoke AWS...";
auto outcome = lambda_->Invoke(invokeRequest);
The invoke succeeds but I get an error:
{"errorMessage":"RequestId: 7c208ba7-c221-430a-b0ca-d67fbfc0e475 Process exited before completing request"}
Log result header:
START RequestId: 7c208ba7-c221-430a-b0ca-d67fbfc0e475 Version: $LATEST
[ERROR] [1930427] LAMBDA_RUNTIME Failed to get next invocation. No Response from endpoint
END RequestId: 7c208ba7-c221-430a-b0ca-d67fbfc0e475
REPORT RequestId: 7c208ba7-c221-430a-b0ca-d67fbfc0e475 Duration: 35.81 ms Billed Duration: 100 ms Memory Size: 128 MB Max Memory Used: 33 MB
RequestId: 7c208ba7-c221-430a-b0ca-d67fbfc0e475 Process exited before completing request
What am I doing differently in the C++ SDK vs the command line that is causing the execution to fail? Alternatively, any hints on how to diagnose this further would be helpful.
Upvotes: 1
Views: 562
Reputation: 3106
I think you need to rewind the stream before passing it to SetBody
.
payload_ss->seekg(0, payload_ss->beg); // rewind the stream
invokeRequest.SetBody(payload_ss);
Upvotes: 1