티스토리 뷰

반응형

python boto3으로 뚝딱인데 C++로 하려니까...

일단 cmake, build 뚝딱뚝딱 해도 안됐음, 그래서 nuget으로 사용하는 법 찾음

 

프로젝트 생성 -> 우클  -> nuget패키지 관리... > 찾아보기 검색-> awssdkcpp-s3 설치

 

1. SET으로 환경변수에 key들 넣어줘도 안 됐음

2. endpointOverride에 문자열 넣으면 uri 에러 났음(Aws::String으로 넣음)

 

bucket delete 예제임 

다른 예제들: https://docs.aws.amazon.com/ko_kr/sdk-for-cpp/v1/developer-guide/examples-s3-buckets.html

 

Creating, Listing, and Deleting Buckets - AWS SDK for C++

Creating, Listing, and Deleting Buckets Every object or file in Amazon Simple Storage Service must reside within a bucket which represents a folder of objects. Each bucket is known by a name that must be globally unique within the AWS ecosystem. For detail

docs.aws.amazon.com

#include "pch.h"
#include <aws/core/auth/AWSCredentialsProvider.h>
#include <aws/core/utils/memory/stl/AWSStringStream.h>
#include <aws/core/utils/HashingUtils.h>
#include <aws/core/utils/StringUtils.h>
#include <aws/s3/S3Client.h>
#include <aws/s3/model/GetObjectRequest.h>
#include <aws/s3/model/PutObjectRequest.h>
#include <aws/s3/model/DeleteObjectRequest.h>
#include <aws/core/Aws.h>
#include <aws/s3/S3Client.h>
#include <aws/s3/model/DeleteBucketRequest.h>

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

const Aws::String AWS_ACCESS_KEY_ID = "acckey";
const Aws::String AWS_SECRET_ACCESS_KEY = "skey";

int main() {
	Aws::SDKOptions options;
	Aws::InitAPI(options);
	Aws::String endp = "kr.object.ncloudstorage.com";
	Aws::Client::ClientConfiguration config;
	config.endpointOverride = endp;
	config.region = "kr-standard";
	config.scheme = Aws::Http::Scheme::HTTP;
	//Aws::S3::S3Client s3_client(config);
	Aws::S3::S3Client s3_client(Aws::Auth::AWSCredentials(AWS_ACCESS_KEY_ID, AWS_SECRET_ACCESS_KEY),
		config);


	Aws::S3::Model::DeleteBucketRequest bucket_request;
	bucket_request.SetBucket("qwesda");

	auto outcome = s3_client.DeleteBucket(bucket_request);

	if (outcome.IsSuccess())
	{
		std::cout << "Done!" << std::endl;
		
	}
	else
	{
		std::cout << "DeleteBucket error: "
			<< outcome.GetError().GetExceptionName() << " - "
			<< outcome.GetError().GetMessage() << std::endl;
	}
	Aws::ShutdownAPI(options);
	getchar();
	return 0;
}

aws-sdk-cpp 못 한게 아쉬움

정리 예정

-----------------------

cmake도 문제 없음, 잘 되는것 확인함

댓글

티스토리 방명록

최근에 올라온 글
최근에 달린 댓글
Total
Today
Yesterday