Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

SQS Queue Creation/ List operations are failing #8313

Open
maheshtirumerla opened this issue Nov 14, 2024 · 1 comment
Open

SQS Queue Creation/ List operations are failing #8313

maheshtirumerla opened this issue Nov 14, 2024 · 1 comment
Labels
debugging Working with user to figure out if there is an issue

Comments

@maheshtirumerla
Copy link

maheshtirumerla commented Nov 14, 2024

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

@maheshtirumerla maheshtirumerla changed the title SQS Queue Creation/ List operation are failing SQS Queue Creation/ List operations are failing Nov 14, 2024
@bblommers
Copy link
Collaborator

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 #8323

@bblommers bblommers added the debugging Working with user to figure out if there is an issue label Nov 16, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
debugging Working with user to figure out if there is an issue
Projects
None yet
Development

No branches or pull requests

2 participants