aws-sdk-cpp icon indicating copy to clipboard operation
aws-sdk-cpp copied to clipboard

S3 CopyObject fails with version id

Open josuegomes opened this issue 1 year ago • 2 comments

Describe the bug

Ubuntu 22.04, GCC 11.2, aws-sdk-cpp 1.9.22 (from vcpkg)

This code (excerpt);

Aws::S3::Model::CopyObjectRequest copyObjectRequest;

auto outcome = s3Client.CopyObject(copyObjectRequest
	.WithCopySource("558007041168/Wedding/lenovelle.jpg?versionId=zm1uOxum.DfrtaVE9opSLgR21orgDN0L")
	.WithBucket("558007041168")
	.WithKey("Wedding/lenovelle1.jpg"));

fails with exception NoSuchKey - The specified key does not exist

Log shows:

[DEBUG] 2022-09-21 19:44:41.290 AWSAuthV4Signer [139753200830464] Canonical Request String: PUT
/Wedding/lenovelle1.jpg

amz-sdk-invocation-id:04F1939E-F0A3-4FD6-BB21-433DB8DA03BA
amz-sdk-request:attempt=1
content-length:0
content-type:application/xml
host:558007041168.s3.eu-central-1.amazonaws.com
x-amz-api-version:2006-03-01
x-amz-content-sha256:UNSIGNED-PAYLOAD
x-amz-copy-source:558007041168/Wedding/lenovelle.jpg%3FversionId%3Dzm1uOxum.DfrtaVE9opSLgR21orgDN0L
x-amz-date:20220921T194441Z

Note how x-amz-copy-source was encoded.

Expected Behavior

No exception.

Current Behavior

Exception NoSuchKey - The specified key does not exist

From the logs:

<Error><Code>NoSuchKey</Code><Message>The specified key does not exist.</Message><Key>Wedding/lenovelle.jpg?versionId=zm1uOxum.DfrtaVE9opSLgR21orgDN0L</Key><RequestId>QG9XH4MMABAZ0858</RequestId><HostId>TXkprRHfwnOHZM3JonCZbOeoNe9WJM+5jAIXSiB1pD1CdCdHGrli3HTi/ZZVPlj+fjiOATeHkGA=</HostId></Error>

Reproduction Steps

#include <iostream>

#include <aws/core/Aws.h>
#include <aws/core/utils/logging/DefaultLogSystem.h>
#include <aws/core/utils/logging/AWSLogging.h>

#include <aws/s3/S3Client.h>
#include <aws/s3/model/CopyObjectRequest.h>

int main()
{
	Aws::SDKOptions options;
	Aws::InitAPI(options);
	{
		Aws::Utils::Logging::InitializeAWSLogging(
			Aws::MakeShared<Aws::Utils::Logging::DefaultLogSystem>("s3copy", Aws::Utils::Logging::LogLevel::Debug, "s3copy-"));

		Aws::Client::ClientConfiguration clientConfiguration;
		clientConfiguration.region = "eu-central-1";

		Aws::S3::S3Client s3Client(clientConfiguration);

		Aws::S3::Model::CopyObjectRequest copyObjectRequest;
		auto outcome = s3Client.CopyObject(copyObjectRequest
			.WithCopySource("558007041168/Wedding/lenovelle.jpg?versionId=zm1uOxum.DfrtaVE9opSLgR21orgDN0L")
			.WithBucket("558007041168")
			.WithKey("Wedding/lenovelle1.jpg"));

		if (outcome.IsSuccess()) {
			std::cout << "Copied\n";
		}
		else {
			std::cout << "CopyObject error: "
					  << outcome.GetError().GetExceptionName() << " - "
					  << outcome.GetError().GetMessage() << std::endl;
		}

		Aws::Utils::Logging::ShutdownAWSLogging();
	}
	Aws::ShutdownAPI(options);
	return 0;
}

Possible Solution

No response

Additional Information/Context

No response

AWS CPP SDK version used

1.9.22 (vcpkg)

Compiler and Version used

gcc 11.2

Operating System and version

Ubuntu 22.04

josuegomes avatar Sep 21 '22 20:09 josuegomes

For reference the same request using AWS CLI:

aws s3api copy-object --debug --copy-source 558007041168/Wedding/lenovelle.jpg?versionId=zm1uOxum.DfrtaVE9opSLgR21orgDN0L --bucket 558007041168 --key Wedding/lenovelle1.jpg

Logs this:

2022-09-21 16:50:02,263 - MainThread - botocore.auth - DEBUG - CanonicalRequest:
PUT
/Wedding/lenovelle1.jpg

host:558007041168.s3.eu-central-1.amazonaws.com
x-amz-content-sha256:e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855
x-amz-copy-source:558007041168/Wedding/lenovelle.jpg?versionId=zm1uOxum.DfrtaVE9opSLgR21orgDN0L
x-amz-date:20220921T195002Z

josuegomes avatar Sep 21 '22 21:09 josuegomes

I'm getting the exact same error on Mac. Looking into the cause of this

jmklix avatar Sep 22 '22 21:09 jmklix

This is fixed with this PR: https://github.com/aws/aws-sdk-cpp/pull/2564

jmklix avatar Feb 06 '24 23:02 jmklix

This issue is now closed. Comments on closed issues are hard for our team to see. If you need more assistance, please open a new issue that references this one.

github-actions[bot] avatar Feb 06 '24 23:02 github-actions[bot]