【发布时间】:2021-10-11 04:37:48
【问题描述】:
我一直在尝试将 MinIO 配置为伪 Amazon S3 提供程序。这样我就可以在开发和测试我的代码时使用 MinIO,但在发布它时仍然使用 Amazon S3。然而,我在尝试使用 MinIO 创建存储桶时遇到的错误是:
Amazon.S3.AmazonS3Exception: The authorization header is malformed; the region is wrong; expecting 'eu-west-2'.
我一直在关注this 教程,我注意到区域端点/ServiceUrl 没有正确设置。这是他们用来创建配置的代码:
var config = new AmazonS3Config
{
RegionEndpoint = RegionEndpoint.USEast1, // MUST set this before setting ServiceURL and it should match the `MINIO_REGION` environment variable.
ServiceURL = "http://localhost:9000", // replace http://localhost:9000 with URL of your MinIO server
ForcePathStyle = true // MUST be true to work correctly with MinIO server
};
看起来不错,但我注意到当设置 RegionEndpoint 时,ServiceUrl 设置为 null,反之亦然。下面来自亚马逊的代码显示了这一点:
public string ServiceURL
{
get => this.serviceURL;
set
{
this.regionEndpoint = (RegionEndpoint) null;
this.probeForRegionEndpoint = false;
this.serviceURL = value;
}
}
public RegionEndpoint RegionEndpoint
{
get
{
if (this.probeForRegionEndpoint)
{
this.RegionEndpoint = ClientConfig.GetDefaultRegionEndpoint();
this.probeForRegionEndpoint = false;
}
return this.regionEndpoint;
}
set
{
this.serviceURL = (string) null;
this.regionEndpoint = value;
this.probeForRegionEndpoint = this.regionEndpoint == null;
}
}
我几乎可以理解亚马逊的这个设计决定,因为他们的服务 URL 包含区域,例如https://dynamodb.us-west-2.amazonaws.com.
我注意到 MinIO 代码中的注释说“// 必须在设置 ServiceURL 之前设置它,并且它应该与 MINIO_REGION 环境变量匹配。”,但根据我的发现,这不是真的.您不能同时设置 ServiceURL 和 RegionEndpoint。
如果我在 RegionEndpoint 之前指定 ServiceUrl,例如:
var config = new AmazonS3Config
{
ServiceURL = "http://localhost:9000", // replace http://localhost:9000 with URL of your MinIO server
RegionEndpoint = RegionEndpoint.EUWest2, // MUST set this before setting ServiceURL and it should match the `MINIO_REGION` environment variable.
ForcePathStyle = true // MUST be true to work correctly with MinIO server
};
然后我得到:
Amazon.S3.AmazonS3Exception: 'The AWS Access Key Id you provided does not exist in our records.'
大概是因为 ServiceUrl 现在为空,默认情况下它会尝试连接到实际的 Amazon Url,而不是 http://localhost。
但是如果我在 ServiceUrl 之前指定 RegionEndoint,就像第一个示例一样,那么我得到:
Amazon.S3.AmazonS3Exception: The authorization header is malformed; the region is wrong; expecting 'eu-west-2'.
大概是因为 RegionEndpoint 现在为空。
我该怎么办?为什么我是唯一有这个问题的人?
当我连接到 Amazon S3 而不是 MinIO 时,我没有这个问题,因为我不需要指定 RegionEndpoint(因为它是从我在安装和配置 Amazon Web 时输入的详细信息中提取的服务命令行集成 (AWS CLI))或 ServiceUrl(因为它为我解决了所有问题)。
感谢阅读
【问题讨论】: