0

I am trying to retrieve the SES account-level suppression list using AWS SDK in .Net Core:

Below is my code:

public class SimpleEmailServiceUtility : ISimpleEmailServiceUtility
{
    private readonly IAmazonSimpleEmailServiceV2 _client;

    public SimpleEmailServiceUtility(IAmazonSimpleEmailServiceV2 client)
    {
        _client = client;
    }

    public async Task<ListSuppressedDestinationsResponse> GetSuppressionList()
    {
        ListSuppressedDestinationsRequest request = new ListSuppressedDestinationsRequest();
        request.PageSize = 10;

        ListSuppressedDestinationsResponse response = new ListSuppressedDestinationsResponse();
        
        try
        {
            response = await _client.ListSuppressedDestinationsAsync(request);
        }
        catch (Exception ex)
        {
            Console.WriteLine("ListSuppressedDestinationsAsync failed with exception: " + ex.Message);
        }

        return response;
    }
}

But it doesn't seem to be working. The request takes too long and then returns empty response or below error if I remove try/catch:

An unhandled exception occurred while processing the request.
TaskCanceledException: A task was canceled.
System.Threading.Tasks.TaskCompletionSourceWithCancellation<T>.WaitWithCancellationAsync(CancellationToken cancellationToken)

TimeoutException: A task was canceled.
Amazon.Runtime.HttpWebRequestMessage.GetResponseAsync(CancellationToken cancellationToken)

Can anyone please guide if I am missing something?

Thank you!

Naveed Ahmed
  • 10,048
  • 12
  • 46
  • 85

2 Answers2

0

I have tested your code and everything works correctly.

using Amazon;
using Amazon.SimpleEmailV2;
using Amazon.SimpleEmailV2.Model;

internal class Program
{
    private async static Task Main(string[] args)
    {
        var client = new AmazonSimpleEmailServiceV2Client("accessKeyId", "secrectAccessKey", RegionEndpoint.USEast1);

        var utility = new SimpleEmailServiceUtility(client);
        var result = await utility.GetSuppressionList();
    }
}

<PackageReference Include="AWSSDK.SimpleEmailV2" Version="3.7.1.127" />

Things that you can check:

  1. Try again, maybe it was a temporary problem.
  2. Try with the latest version that I am using(if not already)
  3. How far are you from the region that you try to get the list? Try making the same request from an EC2 instance in that region.
  • Thanks Цветан Иванов for your reply. I have tried it again, but still same issue. I have also verified and I am also using `V 3.7.1.127` . Its strange that same credentials and region works perfectly when I try it with `aws cli` . Can you please try your code in `RegionEndpoint.USWest2`? – Naveed Ahmed Sep 08 '22 at 19:32
  • @NaveedAhmed It's working with USWest2 and it's far away from my location. When you use the aws cli how long does it take? – Цветан Иванов Sep 09 '22 at 09:22
  • It's instant, and takes max of 1-2 seconds – Naveed Ahmed Sep 09 '22 at 11:36
  • I have below packages: ' – Naveed Ahmed Sep 09 '22 at 11:40
  • BTW if the same accessKeyId and secrectAccessKey is working with aws cli this means that there shouldn't be any issue with the credentials, correct? – Naveed Ahmed Sep 09 '22 at 11:44
  • 1
    Finally found the issue, I was using `awsConfig.DefaultClientConfig.UseHttp = true;` which was causing the issue. Removing it fix the issue and everything seems to be working perfectly now. Thanks for your time and help, really appreicate :) – Naveed Ahmed Sep 09 '22 at 11:59
0

Finally found the issue, I was using awsConfig.DefaultClientConfig.UseHttp = true;' in startup` which was causing the issue. Removing it fixed the issue and everything seems to be working fine now.

Naveed Ahmed
  • 10,048
  • 12
  • 46
  • 85