亚马逊简单通知服务AWSSDK C# - SOS

Lol*_*ace 23 c# sdk amazon-web-services

我正在尝试使用亚马逊的AWSSDK发布C#和简单通知服务.

SDK没有随附的样本,在网上搜索2小时后,网上没有任何样本.我想出了这个,但它抛出的异常不会产生比单个字符串更多的信息,"TopicARN" - 没有内部异常 - nuffin!
如果有人SNS使用AWSSDK通过C#成功发送了一条消息,我很乐意看到即使是最基本的工作示例.我使用的是最新的SDK 1.5x

这是代码:

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);
Run Code Online (Sandbox Code Playgroud)

Pav*_*nov 28

下面是一个示例,它创建主题,设置主题显示名称,为主题订阅电子邮件地址,发送消息并删除主题.请注意,在继续之前,您应该等待/检查电子邮件的两个位置.Client是客户端实例,topicName是一个任意主题名称.

// 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
});
Run Code Online (Sandbox Code Playgroud)

  • AWS官方网站上有各种[文档资源](http://aws.amazon.com/documentation/),例如[Amazon SNS指南入门](http://docs.amazonwebservices.com/sns /latest/gsg/Welcome.html).您还可以在[AWS论坛](https://forums.aws.amazon.com/index.jspa)上找到有用的信息并提出问题.但是,有时它只是有助于加入.NET SDK团队.:) (4认同)