skip to Main Content

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!

2

Answers


  1. Chosen as BEST ANSWER

    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.


  2. 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.
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search