Untitled
unknown
csharp
10 months ago
1.2 kB
7
Indexable
using System;
using System.Collections.Generic;
using System.Threading.Tasks;
using Amazon.SimpleNotificationService;
using Amazon.SimpleNotificationService.Model;
public class SnsPublisher
{
public static async Task PublishMessageAsync()
{
// Initialize the SNS client
var snsClient = new AmazonSimpleNotificationServiceClient();
// Create a publish request with message attributes
var publishRequest = new PublishRequest
{
TopicArn = "arn:aws:sns:us-east-1:123456789012:MyTopic", // replace with your SNS Topic ARN
Message = "Hello, this is a test notification!",
MessageAttributes = new Dictionary<string, MessageAttributeValue>
{
{ "channel", new MessageAttributeValue {
DataType = "String",
StringValue = "email" // could be "sms" or "push" based on user preferences
} }
}
};
// Publish the message to SNS
var response = await snsClient.PublishAsync(publishRequest);
Console.WriteLine("Message published with ID: " + response.MessageId);
}
}
Editor is loading...
Leave a Comment