4

I have an S3 URI, and I need to extract the region, bucket and object key so that I can use the Aws::S3::Model::PutObjectRequest to upload an object.

Does the AWS C++ SDK provide a utility function for doing purpose? Should I use a regular expression?

I note that the AWS Java SDK provides AmazonS3URI, but I haven't found anything similar so far in the C++ SDK.

Many thanks.

Boinst
  • 3,365
  • 2
  • 38
  • 60

2 Answers2

2

The AWS SDK C++ provides Aws::Crt::Io::Uri which is general but you can definitely use it with s3.

    const std::string s3uri("s3://mybucket/sample-file-name");
    Aws::Crt::Io::Uri uri(Aws::Crt::ByteCursor{s3uri.size(), (uint8_t*)s3uri.data()});
    std::cout << "Scheme:" << Aws::Utils::StringUtils::FromByteCursor(uri.GetScheme())
              << std::endl;
    std::cout << "Authority:"
              << Aws::Utils::StringUtils::FromByteCursor(uri.GetAuthority()) << std::endl;
    std::cout << "Path:" << Aws::Utils::StringUtils::FromByteCursor(uri.GetPath())
              << std::endl;

Results in

Scheme:s3
Authority:mybucket
Path:/sample-file-name

Two years late but I hope someone this helps

Something Something
  • 3,999
  • 1
  • 6
  • 21
1

I don't think C++ SDK supports it. But S3 URIs are just those - URIs. So any decent URI parser should be able to parse S3 URIs, your bucket name will be parsed as host and a file key will be parsed as path.

Artem Vovsia
  • 1,520
  • 9
  • 15