I recently have worked on aws-cpp-sdk from AWS service. But unfortunately I couldn't understand how to handle memory because there aren't enough tutorials or examples on the internet.
What I have tried are as follows.
1. built aws-cpp-sdk as a 64bit shared dll for windows x64(exactly win10, vs 2015) using CMake.
2. And used that library in win32 console application to test.
3. But it's complicated while using their SDK.
First attached my code
#include "stdafx.h"
#include <awss3S3Client.h>
#include <awscoreAws.h>
#include <awss3modelPutObjectRequest.h>
using namespace Aws;
using namespace Aws::S3;
using namespace Aws::S3::Model;
static const char* ALLOCATION_TAG = "memory";
static const char* S3_BUCKET_NAME = "XXXXXXXX";
static const char* S3_KEY = "Hello";
int main()
{ Aws::SDKOptions options; Aws::InitAPI(options); Client::ClientConfiguration config; auto mS3Client = Aws::MakeShared<Aws::S3::S3Client>(ALLOCATION_TAG, config); auto requestStream = Aws::MakeShared<Aws::StringStream>("s3-sample"); *requestStream << "Hello World!"; Model::PutObjectRequest request; request.WithKey(S3_KEY).WithBucket(S3_BUCKET_NAME); request.SetBody(requestStream); auto outcome = mS3Client->PutObject(request); bool bRet = false; if (outcome.IsSuccess()) { bRet = true; std::cout << "Put object succeeded" << std::endl; } else { bRet = false; std::cout << "Error while putting Object " << outcome.GetError().GetExceptionName() << " " << outcome.GetError().GetMessage() << std::endl; } Aws::ShutdownAPI(options); return 0;
}
The problem is that when I pass PutObjectRequest request to PutObject function, the variabes of the request are not passed exactly.
In detail, bucket name I put "XXXXXXX" is not available(empty string) in PutObject function in S3Client.cpp file. Attached PutObject function.
PutObjectOutcome S3Client::PutObject(const PutObjectRequest& request) const
{ Aws::StringStream ss; ss << m_uri << "/"; ss << request.GetBucket(); //here exception occured because request.GetBucket() returns empty string. ss << "/"; ss << request.GetKey(); XmlOutcome outcome = MakeRequest(ss.str(), request, HttpMethod::HTTP_PUT); if(outcome.IsSuccess()) { return PutObjectOutcome(PutObjectResult(outcome.GetResult())); } else { return PutObjectOutcome(outcome.GetError()); }
}
I am not sure why the value of Bucket Name isn't passed correctly(maybe it's a memory related problem, i think).
Please help me what and how I should handle memory allocation in this code. Hope the great solutions.
PS: Any links to detailed tutorial would be okay.(Anyway I can't find through googling. :-( )