Amazon Simple Notification Service AWSSDK C# - S.O.S
amazon-web-services, c#, sdk
Solution
Here is a sample that creates a topic, sets a topic display name, subscribes an email address to the topic, sends a message and deletes the topic. Note that there are two spots where you should wait/check your email before continuing. `Client` is the client instance, `topicName` is an arbitrary topic name.
// Create topic
string topicArn = client.CreateTopic(new CreateTopicRequest
{
Name = topicName
}).CreateTopicResult.TopicArn;
// Set display name to a friendly value
client.SetTopicAttributes(new SetTopicAttributesRequest
{
TopicArn = topicArn,
AttributeName = "DisplayName",
AttributeValue = "StackOverflow Sample Notifications"
});
// Subscribe an endpoint - in this case, an email address
client.Subscribe(new SubscribeRequest
{
TopicArn = topicArn,
Protocol = "email",
Endpoint = "sample@example.com"
});
// When using email, recipient must confirm subscription
Console.WriteLine("Please check your email and press enter when you are subscribed...");
Console.ReadLine();
// Publish message
client.Publish(new PublishRequest
{
Subject = "Test",
Message = "Testing testing 1 2 3",
TopicArn = topicArn
});
// Verify email receieved
Console.WriteLine("Please check your email and press enter when you receive the message...");
Console.ReadLine();
// Delete topic
client.DeleteTopic(new DeleteTopicRequest
{
TopicArn = topicArn
});
Problem
I am trying to publish with Amazon's AWSSDK for C# and the Simple Notification Service. There are no samples that come with the SDK and there are no samples anywhere on the web I could find after 2 hours of Googling. I came up with this but it is throwing an exception that yields no more information than the single string, "TopicARN" - no inner exception - nuffin! If anyone has successfully sent a message with `SNS` via C# using the AWSSDK I would love to see even the most rudimentary working example. I am using the latest SDK 1.5x Here's the code: ``` string resourceName = "arn:aws:sns:us-east-1:xxxxxxxxxxxx:StackOverFlowStub"; AmazonSimpleNotificationServiceClient snsclient = new AmazonSimpleNotificationServiceClient(accesskey,secretkey); AddPermissionRequest permissionRequest = new AddPermissionRequest() .WithActionNames("Publish") .WithActionNames(accesskey) .WithActionNames("PrincipleAllowControl") .WithActionNames(resourceName); snsclient.AddPermission(permissionRequest); PublishRequest pr = new PublishRequest(); pr.WithMessage("Test Msg"); pr.WithTopicArn(resourceName); pr.WithSubject("Test Subject"); snsclient.Publish(pr); ```