NServiceBus on AWS Lambda - Publish to SNS Topic help

I’ve been learning about NServiceBus and using it through AWS Lambda. I’ve been following along with the following guide:

and the following blog post:

I’ve implemented a cloud function from Lambda which sends a test message into SQS via NServiceBus, and a lambda service which is triggered by the message being inserted into the queue. Very much like the step-by-step guide. Everything works so far. The problem happens after I handle the message in the lambda service. I’m calling the following method:

await context.Publish(new BasicEvent(message.Id));

I’m assuming that the topic will be automatically created as mentioned in the blog post:

“You can even send commands or publish events using the NServiceBus API. NServiceBus takes care of creating the necessary SQSClient or SNSClient for you. NServiceBus will also manage the cases where one message in a batch fails, making sure that only failed messages are retried and that outgoing messages are only dispatched if the individual message processing succeeds.”

But nothing happens.

Has anyone implemented a successful Command Handler which then publishes successfully to SNS via a AWS Lambda function?

Thanks!

Hi @menkari, welcome to the Particular discussion group.

The NServiceBus SQS/SNS support assumes that subscribers create topics and subscriptions. So, in your case, it’s expected that the message goes nowhere when publishing.

You need to create a subscriber for the published message to see it working as expected. The subscriber will create the topic and the required subscription. At that point, the message will be in the subscriber input queue.

Doing those experiments with Lambas is tricky because you need to start the subscriber to create the required infrastructure or deploy the infrastructure manually, e.g., using the command line tool bundled with the transport.

I’d suggest running both the publisher and the subscriber as console apps from your machine to start playing with NServiceBus.

Let me know if you need any help setting those up.
.m