AWS Lambda C ++ SDK“在完成请求之前退出流程”

时间:2019-08-28 00:40:27

标签: c++ aws-lambda aws-sdk

我创建了一个函数“ gen_MC_calculate_compound”。当我调用aws lambda list-function时,我得到:

{
    "Functions": [
        {
            "FunctionName": "gen_MC_calculate_compound",
            ...
        }
}

此刻是您好世界示例:

#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;
}

我可以使用以下命令从命令行调用它:

aws lambda invoke --function-name gen_MC_calculate_compound out.txt

我得到一个成功的结果:

{
    "StatusCode": 200,
    "ExecutedVersion": "$LATEST"
}

我在以下代码中使用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);

调用成功,但出现错误:

{"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

在C ++ SDK和导致执行失败的命令行中,我做了什么不同的工作?另外,任何有关如何进一步诊断的提示都将有所帮助。

1 个答案:

答案 0 :(得分:1)

我认为您需要先倒流,然后再将其传递到SetBody


        payload_ss->seekg(0, payload_ss->beg); // rewind the stream

        invokeRequest.SetBody(payload_ss);