Apache Ozone + AWS S3 .Net API:PutObject 正在创建存储桶而不是密钥
Apache Ozone + AWS S3 .Net API: PutObject is creating a bucket instead of a key
我正在尝试使用适用于 .NET 的 AWS S3 API 在 apache OZone 中创建密钥。
我尝试创建的密钥必须在我使用 AWS S3 CLI 创建的名为 "test" 的存储桶中。
我的代码:
static async Task WriteFile()
{
AmazonS3Config config = new AmazonS3Config();
config.ServiceURL = "http://myApacheOzoneEndpoint:8744"; // This port is mapped from a docker container to (not the original endpoint port for Ozone)
AWSCredentials credentials = new BasicAWSCredentials("testuser/scm@EXAMPLE.COM", "c261b6ecabf7d37d5f9ded654b1c724adac9bd9f13e247a235e567e8296d2999"); // Credentials must be set but can be random since Ozone doesn't use authentication
AmazonS3Client client = new AmazonS3Client(credentials, config);
using (FileStream fs = File.OpenRead(@"C:\Users\me\path.to.file\image.jpg"))
{
string responseBody = "";
try
{
PutObjectRequest request = new PutObjectRequest
{
BucketName = "test",
Key = "deleteme.jpg",
InputStream = fs
};
PutObjectResponse response = await client.PutObjectAsync(request);
Console.WriteLine($"Result: {response.HttpStatusCode.ToString()}");
}
catch (AmazonS3Exception e)
{
Console.WriteLine("Error encountered ***. Message:'{0}' when writing an object", e.Message);
}
catch (Exception e)
{
Console.WriteLine("Unknown encountered on server. Message:'{0}' when writing an object", e.Message);
}
}
}
此代码返回 200 代码错误(正常),如果我从 API 调用 GetObjectAsync,我会得到一个带有元数据的 HTML 结果(但无法读取文件内容暂时)
然后我转到 Apache Ozone 并在 ozone 中执行这些命令 shell:
bash-4.2$ ozone s3 path test
Volume name for S3Bucket is : s3c89e813c80ffcea9543004d57b2a1239
Ozone FileSystem Uri is : o3fs://test.s3c89e813c80ffcea9543004d57b2a1239
bash-4.2$ ozone sh bucket list /s3c89e813c80ffcea9543004d57b2a1239
[ {
"volumeName" : "s3c89e813c80ffcea9543004d57b2a1239",
"bucketName" : "test",
"createdOn" : "Wed, 01 Apr 2020 08:06:40 GMT",
"acls" : null,
"versioning" : "DISABLED",
"storageType" : "DISK",
"encryptionKeyName" : "N/A"
}, {
"volumeName" : "s3c89e813c80ffcea9543004d57b2a1239",
"bucketName" : "deleteme.jpg",
"createdOn" : "Tue, 31 Mar 2020 10:57:26 GMT",
"acls" : null,
"versioning" : "DISABLED",
"storageType" : "DISK",
"encryptionKeyName" : "N/A"
} ]
bash-4.2$ ozone sh key list /s3c89e813c80ffcea9543004d57b2a1239/test => This command returns only keys that have been put from AWS S3 CLI
如您所见,该对象被创建为用于 S3 的 Ozone 卷内的新存储桶,而不是被创建为 test
存储桶下方的新键。如果我尝试从 AWS S3 Cli 中输入密钥,它会按预期工作
发生了什么事?
仅供参考,我从 Java API 做了同样的例子,但同样的问题出现了!
谢谢
Ozone s3-gateway 默认使用 path-style addressing 而更新的 sdk 库使用虚拟托管寻址。最快的解决方案是切换到路径样式:
// AmazonS3Config config = new AmazonS3Config();
config.ForcePathStyle = true;
或者,如文档中所述,您可以在 ozone 中启用虚拟托管模式。
请注意 aws s3 中的路径样式 is going to be deprecated。
我正在尝试使用适用于 .NET 的 AWS S3 API 在 apache OZone 中创建密钥。
我尝试创建的密钥必须在我使用 AWS S3 CLI 创建的名为 "test" 的存储桶中。
我的代码:
static async Task WriteFile()
{
AmazonS3Config config = new AmazonS3Config();
config.ServiceURL = "http://myApacheOzoneEndpoint:8744"; // This port is mapped from a docker container to (not the original endpoint port for Ozone)
AWSCredentials credentials = new BasicAWSCredentials("testuser/scm@EXAMPLE.COM", "c261b6ecabf7d37d5f9ded654b1c724adac9bd9f13e247a235e567e8296d2999"); // Credentials must be set but can be random since Ozone doesn't use authentication
AmazonS3Client client = new AmazonS3Client(credentials, config);
using (FileStream fs = File.OpenRead(@"C:\Users\me\path.to.file\image.jpg"))
{
string responseBody = "";
try
{
PutObjectRequest request = new PutObjectRequest
{
BucketName = "test",
Key = "deleteme.jpg",
InputStream = fs
};
PutObjectResponse response = await client.PutObjectAsync(request);
Console.WriteLine($"Result: {response.HttpStatusCode.ToString()}");
}
catch (AmazonS3Exception e)
{
Console.WriteLine("Error encountered ***. Message:'{0}' when writing an object", e.Message);
}
catch (Exception e)
{
Console.WriteLine("Unknown encountered on server. Message:'{0}' when writing an object", e.Message);
}
}
}
此代码返回 200 代码错误(正常),如果我从 API 调用 GetObjectAsync,我会得到一个带有元数据的 HTML 结果(但无法读取文件内容暂时)
然后我转到 Apache Ozone 并在 ozone 中执行这些命令 shell:
bash-4.2$ ozone s3 path test
Volume name for S3Bucket is : s3c89e813c80ffcea9543004d57b2a1239
Ozone FileSystem Uri is : o3fs://test.s3c89e813c80ffcea9543004d57b2a1239
bash-4.2$ ozone sh bucket list /s3c89e813c80ffcea9543004d57b2a1239
[ {
"volumeName" : "s3c89e813c80ffcea9543004d57b2a1239",
"bucketName" : "test",
"createdOn" : "Wed, 01 Apr 2020 08:06:40 GMT",
"acls" : null,
"versioning" : "DISABLED",
"storageType" : "DISK",
"encryptionKeyName" : "N/A"
}, {
"volumeName" : "s3c89e813c80ffcea9543004d57b2a1239",
"bucketName" : "deleteme.jpg",
"createdOn" : "Tue, 31 Mar 2020 10:57:26 GMT",
"acls" : null,
"versioning" : "DISABLED",
"storageType" : "DISK",
"encryptionKeyName" : "N/A"
} ]
bash-4.2$ ozone sh key list /s3c89e813c80ffcea9543004d57b2a1239/test => This command returns only keys that have been put from AWS S3 CLI
如您所见,该对象被创建为用于 S3 的 Ozone 卷内的新存储桶,而不是被创建为 test
存储桶下方的新键。如果我尝试从 AWS S3 Cli 中输入密钥,它会按预期工作
发生了什么事?
仅供参考,我从 Java API 做了同样的例子,但同样的问题出现了!
谢谢
Ozone s3-gateway 默认使用 path-style addressing 而更新的 sdk 库使用虚拟托管寻址。最快的解决方案是切换到路径样式:
// AmazonS3Config config = new AmazonS3Config();
config.ForcePathStyle = true;
或者,如文档中所述,您可以在 ozone 中启用虚拟托管模式。
请注意 aws s3 中的路径样式 is going to be deprecated。