请教用AWS的C++版SDK开发所遇到的问题,在线等!

wxp545 2016-04-13 10:46:36
我刚开始用AWS的C++版SDK开发,目的是在Linux环境下,开发一个调用AWS-SDK上传文件到云端的功能模块。源码包是aws-sdk-cpp-master.zip,我已将源码包编译安装成功。但由于C++的调用例程几乎没有,我看那些接口代码也看得一头雾水。我在官网上(https://aws.amazon.com/cn/blogs/developer/using-cmake-exports-with-the-aws-sdk-for-c/)找到这么一段例程,我将这段代码保存为文件TestUseAWS.cpp:

#include <aws/s3/S3Client.h>
#include <aws/s3/model/PutObjectRequest.h>
#include <aws/s3/model/GetObjectRequest.h>
#include <aws/core/utils/memory/stl/AwsStringStream.h>

using namespace Aws::S3;
using namespace Aws::S3::Model;

static const char* KEY = "s3_cpp_sample_key";
static const char* BUCKET = "s3-cpp-sample-bucket";

int main()
{
S3Client client;

//first put an object into s3
PutObjectRequest putObjectRequest;
putObjectRequest.WithKey(KEY)
.WithBucket(BUCKET);

//this can be any arbitrary stream (e.g. fstream, stringstream etc...)
auto requestStream = Aws::MakeShared<Aws::StringStream>("s3-sample");
*requestStream << "Hello World!";

//set the stream that will be put to s3
putObjectRequest.SetBody(requestStream);

auto putObjectOutcome = client.PutObject(putObjectRequest);

if(putObjectOutcome.IsSuccess())
{
std::cout << "Put object succeeded" << std::endl;
}
else
{
std::cout << "Error while putting Object " << putObjectOutcome.GetError().GetExceptionName() <<
" " << putObjectOutcome.GetError().GetMessage() << std::endl;
}

//now get the object back out of s3. The response stream can be overridden here if you want it to go directly to
// a file. In this case the default string buf is exactly what we want.
GetObjectRequest getObjectRequest;
getObjectRequest.WithBucket(BUCKET)
.WithKey(KEY);

auto getObjectOutcome = client.GetObject(getObjectRequest);

if(getObjectOutcome.IsSuccess())
{
std::cout << "Successfully retrieved object from s3 with value: " << std::endl;
std::cout << getObjectOutcome.GetResult().GetBody().rdbuf() << std::endl << std::endl;;
}
else
{
std::cout << "Error while getting object " << getObjectOutcome.GetError().GetExceptionName() <<
" " << getObjectOutcome.GetError().GetMessage() << std::endl;
}

return 0;
}
以上代码在我机器上都编译连接通过了,但在运行时报错,我输入的命令为:
(1)g++ -c -w -std=c++11 -I aws-sdk-cpp-master/aws-cpp-sdk-core/include -I aws-sdk-cpp-master/aws-cpp-sdk-s3/include TestUseAWS.cpp

(2)g++ -o TestUseAWS -L /usr/local/lib/linux/ia32 TestUseAWS.o -laws-cpp-sdk-core -laws-cpp-sdk-s3

(3)Export LD_LIBRARY_PATH=/usr/local/lib/linux/ia32:$LD_LIBRARY_PATH

(4)./TestUseAWS

报错为:
*** Error in './TestUseAWS':free():invalid pointer:0x00e31064 *** Aborted
有以下疑问:
(1)设断点发现,在第一句S3Client client;就报错了,不知道是怎么回事;
(2)从putObjectRequest.WithKey(KEY).WithBucket(BUCKET);这一句来看,好像是只需要提供Key和BUCKET就可以将信息PUT上去了,但登录AWS难道不需要账户名吗?
请问论坛里有哪位大神用过C++的AWS-SDK,能帮忙解答下吗?另外,有无关于用C++SDK的一些资料或方法可以分享,万分感谢!
...全文
11001 8 打赏 收藏 转发到动态 举报
写回复
用AI写文章
8 条回复
切换为时间正序
请发表友善的回复…
发表回复
hanqingwu 2020-01-06
  • 打赏
  • 举报
回复
key和bucket 要先创建好,才能用, 当然要最先去注册帐号。
legend1975 2019-09-19
  • 打赏
  • 举报
回复
我碰到过类似问题,你需要把SDK重新编译一遍加上选项-DCUSTOM_MEMORY_MANAGEMENT=OFF。
书香门第 2018-05-31
  • 打赏
  • 举报
回复
AWS是使用credentials来识别身份的,所以你要先注册一个AWS的账号,第一年很多服务免费使用,然后用你账号的public security key 和 private security key在你的系统上配置credentials。你可以参考:https://docs.aws.amazon.com/sdk-for-cpp/v1/developer-guide/credentials.html 另外,其它使用c++开发aws的例子也可以参考该页面的其它链接,讲的更系统。
ginkgo_LHJ 2018-05-14
  • 打赏
  • 举报
回复
能说一下怎么在linux下编译安装aws-sdk-cpp源码包?
qq_36021561 2016-11-16
  • 打赏
  • 举报
回复
能说一下怎么在linux下编译安装aws-sdk-cpp源码包?
qq_18300579 2016-09-09
  • 打赏
  • 举报
回复
key和bucket是要自己去申请的吧,还是说例程上面那个就可以用
qq_18300579 2016-09-09
  • 打赏
  • 举报
回复
兄弟,我也遇到了一样的问题,也是这个例程,你这个问题是怎么解决掉的 我的显示 can not connect to endpoint

409

社区成员

发帖
与我相关
我的任务
社区描述
AWS
社区管理员
  • AWS
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧