/// <summary>
/// Creates a user account for SNS
/// </summary>
/// <param name="userName">The user to create a SNS account for</param>
/// <param name="number">The user's phone number</param>
private void CreateSNSAccount(String userName, String number)
{
AmazonSimpleNotificationServiceClient client = new AmazonSimpleNotificationServiceClient();
//Create topic first.
CreateTopicRequest request = new CreateTopicRequest
{
Name = userName
};
try
{
CreateTopicResponse response = client.CreateTopic(request);
CreateTopicResult result = response.CreateTopicResult;
String[] strings = new String[1];
strings[0] = "Success! Assigned ARN is: " + result.TopicArn + "\n";
TempData["result"] = strings;
}
catch (Exception e)
{
TempData["error"] = e.Message;
}
String arn = "arn:aws:sns:us-east-1:727060774285:" + userName;
SetTopicAttributesRequest request2 = new SetTopicAttributesRequest
{
AttributeName = "DisplayName",
AttributeValue = "Cookbook",
TopicArn = arn
};
try
{
SetTopicAttributesResponse response = client.SetTopicAttributes(request2);
ResponseMetadata result = response.ResponseMetadata;
Console.WriteLine(result.RequestId);
}
catch (Exception e)
{
Console.WriteLine(e.Message);
}
//Add SMS number to topic.
SubscribeRequest request3 = new SubscribeRequest
{
TopicArn = arn,
Endpoint = number,
Protocol = "sms"
};
try
{
SubscribeResponse response = client.Subscribe(request3);
SubscribeResult result = response.SubscribeResult;
string resultSubscribe = "Success! Subscription Arn is: " + result.SubscriptionArn + "\n";
Console.WriteLine(resultSubscribe);
}
catch (Exception e)
{
Console.WriteLine(e.Message);
}
}