0
我想從使用S3 C++接口的lambda中訪問AWS S3。來自lambdas的C++ AWS S3接口
我創建了一個將對象寫入S3的簡單測試。測試在常規VM上運行良好,但在lambda上運行時失敗。
我已經確定了測試運行successfuly直到實際把操作:
auto put_object_outcome = s3_client.PutObject(putObjectRequest);
一旦執行打這條線的過程中成功終止。 PutObject調用後的任何行都不會執行。
任何想法可能會發生什麼?在lambdas上使用C++接口的任何例子也是值得讚賞的。
編輯:
我已經確定代碼在調用未能curl_easy_perform這表明這是捲曲水平的問題。
我的代碼:
Aws::SDKOptions options;
void initialize_aws() {
Aws::InitAPI(options);
}
Aws::S3::S3Client create_client() {
Aws::Client::ClientConfiguration clientConfig;
clientConfig.scheme = Aws::Http::Scheme::HTTPS;
clientConfig.region = Aws::Region::US_WEST_2;
Aws::S3::S3Client s3_client(clientConfig);
return s3_client;
}
bool put_object(uint64_t id, Aws::S3::S3Client& s3_client,
const std::string& bucket_name, const std::string& object) {
std::string key_name = std::to_string(id);
Model::PutObjectRequest putObjectRequest;
putObjectRequest.WithBucket(bucket_name)
.WithKey(key_name);
auto ss = Aws::MakeShared<Aws::StringStream>("TAG");
*ss << object;
ss->flush();
putObjectRequest.SetBody(ss);
// fails here
auto put_object_outcome = s3_client.PutObject(putObjectRequest);
if (put_object_outcome.IsSuccess()) {
return true;
}
else {
std::cout << "PutObject error: " <<
put_object_outcome.GetError().GetExceptionName() << " " <<
put_object_outcome.GetError().GetMessage() << std::endl;
return false;
}
return false;
}
int main(int argc, char** argv) {
initialize_aws();
auto client = create_client();
bool success = put_object(0, client, "bucket_aws_s3_cpp", "1234567");
shutdown_aws();
return 0;
}
請發佈您的失敗的lambda代碼。有很多事情可能會出錯,很難確定哪裏出了問題。 – Kannaiyan
謝謝你的建議。剛剛做到了。 – JC1