【发布时间】:2020-11-21 12:19:46
【问题描述】:
我正在尝试在 aws c++ 运行时上运行一个简单的示例,但是当我调用 lambda 函数时,它会不断出现段错误。首先,以下示例中显示的示例:https://aws.amazon.com/blogs/compute/introducing-the-c-lambda-runtime/ 工作正常。所以,现在,我从一个桶中取一些东西,如下所示:
#include <aws/core/Aws.h>
#include <aws/core/client/ClientConfiguration.h>
#include <aws/core/auth/AWSCredentialsProvider.h>
#include <aws/s3/S3Client.h>
#include <aws/s3/model/GetObjectRequest.h>
#include <awsdoc/s3/s3_examples.h>
#include <vector>
#include <rapidcsv.h>
#include <torch/torch.h>
#include <torch/script.h> // One-stop header.
#include <iostream>
#include <math.h>
#include <memory>
#include <aws/lambda-runtime/runtime.h>
using namespace torch::indexing;
using namespace Aws::Utils;
using namespace aws::lambda_runtime;
char const TAG[] = "LAMBDA_ALLOC";
static invocation_response my_handler(invocation_request const &req)
{
if (req.payload.length() > 42)
{
return invocation_response::failure("error message here" /*error_message*/,
"error type here" /*error_type*/);
}
Aws::SDKOptions options;
Aws::InitAPI(options);
const Aws::String bucket_name("buckname");
const Aws::String object_name("fname");
Aws::S3::S3Client s3_client;
Aws::S3::Model::GetObjectRequest object_request;
object_request.SetBucket(bucket_name);
object_request.SetKey(object_name);
Aws::S3::Model::GetObjectOutcome get_object_outcome =
s3_client.GetObject(object_request);
auto &retrieved_file = get_object_outcome.GetResultWithOwnership().GetBody();
rapidcsv::Document doc(retrieved_file, rapidcsv::LabelParams(-1, -1)); /// this is where the problem is.
const Aws::String objectKey2("model.tar");
Aws::S3::S3Client s3_client2;
Aws::S3::Model::GetObjectRequest object_request2;
object_request2.SetBucket(bucket_name);
object_request2.SetKey(objectKey2);
Aws::S3::Model::GetObjectOutcome get_object_outcome2 =
s3_client2.GetObject(object_request2);
auto &retrieved_file2 = get_object_outcome2.GetResultWithOwnership().GetBody();
torch::jit::script::Module module;
module = torch::jit::load(retrieved_file2); /// this is also where the problem is.
std::cout << "Model Load ok\n";
Aws::ShutdownAPI(options);
return invocation_response::success(tensor_string /*payload*/,
"application/json" /*MIME type*/);
}
int main()
{
run_handler(my_handler);
return 0;
}
问题是,当我在本地(debian、cmake)运行它时,它可以按预期编译和工作,但是当我为 aws 运行时编译它时,我得到了 seg 错误。
我已将问题缩小到两行:
rapidcsv::Document doc(retrieved_file, rapidcsv::LabelParams(-1, -1)); /// this is where the problem is.
还有,
module = torch::jit::load(retrieved_file2); /// this is also where the problem is.
我从这里只使用 rapidcsv 标头库:https://github.com/d99kris/rapidcsv,正如我所说,它在本地运行良好。
我怀疑运行时不知何故无法找到 rapidcsv(但这仍然无法解释为什么它在 module = torch::jit::load(retrieved_file2); 上出现段错误:(
任何指针都会很棒!
【问题讨论】:
-
get_object_outcome.GetResultWithOwnership()不返回 RAII 对象(大部分立即销毁),使auto &retrieved_file悬空引用? -
示例似乎改用
GetResult()。 -
@JaI 将立即尝试这个.. 但它如何在本地工作?
-
@Jarod42:你能告诉我
getResult()的用处吗? -
@Jarod42 是的,我在文档中看到它:github.com/awslabs/aws-lambda-cpp/blob/master/examples/s3/…
标签: c++ amazon-web-services aws-lambda