publish to sns in csharp

To publish a message to an SNS topic in C#, use the Amazon Web Services (AWS) SDK for .NET.

First, install the AWS SDK for .NET using NuGet:

main.cs
Install-Package AWSSDK.SNS
27 chars
2 lines

Then create an instance of the AmazonSimpleNotificationServiceClient class and call its PublishAsync method, passing in the topic arn and message text as parameters:

main.cs
var snsClient = new AmazonSimpleNotificationServiceClient();

var topicArn = "arn:aws:sns:us-west-2:123456789012:MyTopic";
var message = "Hello, world!";

var response = await snsClient.PublishAsync(topicArn, message);
219 chars
7 lines

Make sure to replace the topicArn value with the actual ARN of your SNS topic.

The PublishAsync method returns a PublishResponse object, which contains information about the published message (such as its message ID).

related categories

gistlibby LogSnag