.net-core-2.1aws-sdk-net

Is there a way to determine AWS SES service availability in a region?


Is there a way to determine if ses has a local region available using AWS SDK? After registering e-mail service with Core Middleware services.AddAWSService<IAmazonSimpleEmailService>() I want to find and assign the SES local region to e-mail service if there is one available. Using .Net Core 2.1 and AWS SDK. Thank you!


Solution

  • I believe this link contains information you are interested in - https://aws.amazon.com/blogs/aws/new-query-for-aws-regions-endpoints-and-more-using-aws-systems-manager-parameter-store/

    Here’s how to get the list of regions where a service (Amazon Athena, in this case) is available:

    $ aws ssm get-parameters-by-path \
      --path /aws/service/global-infrastructure/services/athena/regions --output json | \
      jq .Parameters[].Value
    "ap-northeast-2"
    "ap-south-1"
    "ap-southeast-2"
    "ca-central-1"
    "eu-central-1"
    "eu-west-1"
    "eu-west-2"
    "us-east-1"
    "us-east-2"
    "us-gov-west-1"
    "ap-northeast-1"
    "ap-southeast-1"
    "us-west-2"
    

    https://www.nuget.org/packages/AWSSDK.SimpleSystemsManagement/ NuGet package can be used to achieve same via .NET SDK. For your example the code to get the set of regions where SES is available can look like

    var client = new AmazonSimpleSystemsManagementClient(...);
    var path = "/aws/service/global-infrastructure/services/ses/regions";
    var response = await client.GetParametersByPathAsync(new GetParametersByPathRequest
    {
        Path = path
    }).ConfigureAwait(false);
    var regions = new HashSet<string>(response.Parameters.Select(x => x.Value));
    
    while (!string.IsNullOrWhiteSpace(response.NextToken))
    {
        response = await client.GetParametersByPathAsync(new GetParametersByPathRequest
        {
            Path = path,
            NextToken = response.NextToken
        }).ConfigureAwait(false);
    
        foreach (var parameter in response.Parameters) regions.Add(parameter.Value);
    }