I've been trying to configure MinIO for use as a pseudo Amazon S3 provider. This is so that I can use MinIO when developing and testing my code, but still use Amazon S3 when it comes to releasing it. However the error that I've been getting when trying to create a bucket using MinIO is:
Amazon.S3.AmazonS3Exception: The authorization header is malformed; the region is wrong; expecting 'eu-west-2'.
I've been following this tutorial and I've noticed that the Region Endpoint/ServiceUrl doesn't get set properly. This is the code that they use to create the config:
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
};
It looks fine but I've noticed that when the RegionEndpoint is set, then the ServiceUrl is set to null, and visa-versa. The code from Amazon below shows this:
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;
}
}
I can just about understand this design decision from Amazon since their Service URLs contain regions, e.g. https://dynamodb.us-west-2.amazonaws.com.
I've noticed that a comment in the MinIO code says "// MUST set this before setting ServiceURL and it should match the MINIO_REGION
environment variable.", but from what I've found, this isn't true. You can't set both the ServiceURL and the RegionEndpoint.
If I specify the ServiceUrl before the RegionEndpoint, e.g.:
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
};
then I get:
Amazon.S3.AmazonS3Exception: 'The AWS Access Key Id you provided does not exist in our records.'
presumably because the ServiceUrl is now null and by default it tries to connect to an actual Amazon Url rather than http://localhost.
But if I specify the RegionEndoint before the ServiceUrl, like the first example, then I get:
Amazon.S3.AmazonS3Exception: The authorization header is malformed; the region is wrong; expecting 'eu-west-2'.
presumably because the RegionEndpoint is now null.
What do I do? And why am I the only person with this problem?
When I connect to the Amazon S3 rather than MinIO, I don't have this problem because I don't need to specify the RegionEndpoint (because it picks this up from the details that I entered when installing and configuring the Amazon Web Services Command Line Integration (AWS CLI)) or the ServiceUrl (because it works it all out for me).
Thanks for reading