When utilizing the .Net AWS SDK for S3, I've noticed that by default when talking to a bucket in us-east-1, that it is utilizing the legacy global endpoint BUCKETNAME.s3.amazonaws.com
rather then the regional endpoint BUCKETNAME.s3.us-east-1.amazonaws.com
.
How do I force the SDK to utilize the regional endpoint?
Example .Net 6 code:
using Amazon;
using Amazon.Runtime;
using Amazon.S3;
AmazonS3Config config = new Amazon.S3.AmazonS3Config();
config.RegionEndpoint = RegionEndpoint.GetBySystemName("us-east-1");
Console.WriteLine($"S3 Client Service URL: {config.DetermineServiceURL()}");
S3 Client Service URL: https://s3.amazonaws.com/
CodePudding user response:
You'll need to tell the client to explicitly utilize the regional endpoint rather than the legacy global endpoint which is the default.
config.USEast1RegionalEndpointValue = S3UsEast1RegionalEndpointValue.Regional;
By modifying the code with this change:
using Amazon;
using Amazon.Runtime;
using Amazon.S3;
AmazonS3Config config = new Amazon.S3.AmazonS3Config();
config.RegionEndpoint = RegionEndpoint.GetBySystemName("us-east-1");
config.USEast1RegionalEndpointValue = S3UsEast1RegionalEndpointValue.Regional;
Console.WriteLine($"S3 Client Service URL: {config.DetermineServiceURL()}");
You now get the regional endpoint service url:
S3 Client Service URL: https://s3.us-east-1.amazonaws.com/
CodePudding user response:
Set the USEast1RegionalEndpointValue
property on the AmazonS3Config
object to S3UsEast1RegionalEndpointValue.Regional
.
This will force the routing of us-east-1
S3 requests to the regional endpoint instead of the legacy global endpoint.
using Amazon;
using Amazon.Runtime;
using Amazon.S3;
AmazonS3Config config = new AmazonS3Config
{
USEast1RegionalEndpointValue = S3UsEast1RegionalEndpointValue.Regional,
RegionEndpoint = RegionEndpoint.USEast1
};
Console.WriteLine($"S3 Client Service URL: {config.DetermineServiceURL()}");
S3 Client Service URL: https://s3.us-east-1.amazonaws.com/