getmoto / moto

A library that allows you to easily mock out tests based on AWS infrastructure.
http://docs.getmoto.org/en/latest/
Apache License 2.0
7.67k stars 2.06k forks source link

SQS Queue Creation/ List operations are failing #8313

Open maheshtirumerla opened 1 week ago

maheshtirumerla commented 1 week ago

I am trying to create an SQS queue using Moto (AWS local mock service) in C#, but the queue creation fails (Even same for List oberations). The CreateQueueAsync method always returns null or an error, even though I am using the correct endpoint for the Moto server.

I have started the Moto server using Docker (or other methods) at http://127.0.0.1:5000.

I created an AmazonSQSClient in C# to point to the Moto server:

var sqsClient = new AmazonSQSClient(new AnonymousAWSCredentials(),
    new AmazonSQSConfig
    {
        ServiceURL = "http://127.0.0.1:5000" // Moto server URL
    });

I called the CreateQueueAsync method to create a new SQS queue:

public async Task Set_AWS_SQS_QUEUES_IN_MOTO()
{

    // Create an SQS client connected to the local moto server
    var sqsClient = new AmazonSQSClient(new AnonymousAWSCredentials(),
        new AmazonSQSConfig
        {
            // Use the local Moto server URL
            ServiceURL = "http://127.0.0.1:5000",

        });

    // Create the queue and get the response
    var createQueueResponse = await CreateQueueAsync(sqsClient);

}

private static async Task<CreateQueueResponse?> CreateQueueAsync(AmazonSQSClient sqsClient)
{
    try
    {
        // Define the queue parameters
        var createQueueRequest = new CreateQueueRequest
        {
            QueueName = "MyQueue"
        };

        var createQueueResponse = await sqsClient.CreateQueueAsync(createQueueRequest);

        // Return the response if the queue creation is successful
        return createQueueResponse;
    }
    catch (AmazonSQSException sqsEx)
    {
        // Specific exception handling for Amazon SQS errors
        Console.WriteLine($"SQS error occurred: {sqsEx.Message}");
        Console.WriteLine($"Error Code: {sqsEx.ErrorCode}");
        Console.WriteLine($"Error Type: {sqsEx.ErrorType}");
        Console.WriteLine($"Request ID: {sqsEx.RequestId}");
    }
    catch (Exception ex)
    {
        // Handle any other general exceptions
        Console.WriteLine($"An unexpected error occurred: {ex.Message}");
        Console.WriteLine($"Stack Trace: {ex.StackTrace}");
    }

    // Return null if there was an error
    return null;
}

The queue creation fails and returns null.

Additionally, I get this output

2024-11-14 09:35:44 - POST / HTTP/1.1 200 OK 2024-11-14 09:36:10 - POST / HTTP/1.1 200 OK

bblommers commented 1 week ago

Hi @maheshtirumerla, what error does the AWS SDK return? In your example, I would expect to see some output from Console.WriteLine($"SQS error occurred: {sqsEx.Message}"); if there was an error.

How do you start the MotoServer, using which command?

FWIW, I've added this sample as a test case to our CI system, and that seems to pass - see https://github.com/getmoto/moto/pull/8323