private static void RetrieveAllTopics(AmazonSimpleNotificationServiceClient sns) { Console.WriteLine("Retrieving all topics..."); var listTopicsRequest = new ListTopicsRequest(); ListTopicsResponse listTopicsResponse; do { listTopicsResponse = sns.ListTopics(listTopicsRequest); foreach (var topic in listTopicsResponse.Topics) { Console.WriteLine(" Topic: {0}", topic.TopicArn); // Get topic attributes var topicAttributes = sns.GetTopicAttributes(new GetTopicAttributesRequest { TopicArn = topic.TopicArn }).Attributes; if (topicAttributes.Count > 0) { Console.WriteLine(" Topic attributes"); foreach (var topicAttribute in topicAttributes) { Console.WriteLine(" -{0} : {1}", topicAttribute.Key, topicAttribute.Value); } } Console.WriteLine(); } listTopicsRequest.NextToken = listTopicsResponse.NextToken; } while (listTopicsResponse.NextToken != null); }
/// <summary> /// Notification configuration window load event /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void NcWindow_Loaded(object sender, RoutedEventArgs e) { try { AmazonAutoScalingConfig config = new AmazonAutoScalingConfig(); config.ServiceURL = ((ViewModel)this.DataContext).Region.Url; AmazonAutoScalingClient client = new AmazonAutoScalingClient(config); DescribeAutoScalingNotificationTypesRequest dasntreq = new DescribeAutoScalingNotificationTypesRequest(); DescribeAutoScalingNotificationTypesResponse dasntresp = client.DescribeAutoScalingNotificationTypes(dasntreq); foreach (string asnt in dasntresp.DescribeAutoScalingNotificationTypesResult.AutoScalingNotificationTypes) { this.notificationTypes.Add(asnt); } AmazonSimpleNotificationServiceConfig snsconfig = new AmazonSimpleNotificationServiceConfig(); config.ServiceURL = ((ViewModel)this.DataContext).Region.Url; AmazonSimpleNotificationServiceClient snsclient = new AmazonSimpleNotificationServiceClient(snsconfig); ListTopicsRequest ltrequest = new ListTopicsRequest(); ListTopicsResponse ltresp = snsclient.ListTopics(ltrequest); foreach (Topic topic in ltresp.ListTopicsResult.Topics) { this.snstopics.Add(topic.TopicArn); } rlbNcTypes.ItemsSource = this.notificationTypes; cboTopics.ItemsSource = this.snstopics; } catch { MessageBox.Show(Window.GetWindow(this), "Error occured while loading the notification configuration options.", "Error", MessageBoxButton.OK); this.Close(); } }
// public List<PublishResponse> Submit(FormData data) public async Task <IHttpActionResult> Submit(FormatException data) { IHttpActionResult result = null; string accessKey = String.IsNullOrEmpty(System.Configuration.ConfigurationManager.AppSettings["AWSAccessKey"].ToString()) ? string.Empty : System.Configuration.ConfigurationManager.AppSettings["AWSAccessKey"].ToString(); string secretKey = String.IsNullOrEmpty(System.Configuration.ConfigurationManager.AppSettings["AWSSecretKey"].ToString()) ? string.Empty : System.Configuration.ConfigurationManager.AppSettings["AWSSecretKey"].ToString(); var client = new AmazonSimpleNotificationServiceClient(accessKey, secretKey, Amazon.RegionEndpoint.USEast1); var request = new ListTopicsRequest(); var listTopicsResponse = client.ListTopics(request); List <PublishResponse> publishResponses = new List <PublishResponse>(); foreach (var topic in listTopicsResponse.Topics) { publishResponses.Add(client.Publish(new PublishRequest { TopicArn = topic.TopicArn, Message = "This is a test from the ContactUs Web MVC Controller" }) ); } return(result); }
public override void Invoke(AWSCredentials creds, RegionEndpoint region, int maxItems) { AmazonSimpleNotificationServiceConfig config = new AmazonSimpleNotificationServiceConfig(); config.RegionEndpoint = region; ConfigureClient(config); AmazonSimpleNotificationServiceClient client = new AmazonSimpleNotificationServiceClient(creds, config); ListTopicsResponse resp = new ListTopicsResponse(); do { ListTopicsRequest req = new ListTopicsRequest { NextToken = resp.NextToken }; resp = client.ListTopics(req); CheckError(resp.HttpStatusCode, "200"); foreach (var obj in resp.Topics) { AddObject(obj); } }while (!string.IsNullOrEmpty(resp.NextToken)); }
public string GetTopic(string topic) { ListTopicsResponse tmp = client.ListTopics(); //on va storer le arn dans la db pour le moment si le topic existe ça retourne le topic sinon le crée CreateTopicResponse x = client.CreateTopic(topic); return(x.TopicArn); }
public static IEnumerable <string> ListTopicArns() { using (var client = new AmazonSimpleNotificationServiceClient(Settings.AccessKey, Settings.Secret)) { var response = client.ListTopics(new ListTopicsRequest()); return(response.Topics.Select(x => x.TopicArn).ToList()); } }
// //==================================================================================================== /// <summary> /// Get a list of topics for this app. /// </summary> /// <param name="core"></param> /// <returns></returns> public static List <string> getTopicList(CoreController core, AmazonSimpleNotificationServiceClient snsClient) { var result = new List <string>(); var listTopicsResponse = snsClient.ListTopics(); foreach (var topic in listTopicsResponse.Topics) { result.Add(topic.ToString()); } return(result); }
virtual public bool AppMode_TestSnsAccess(RegionEndpoint regionEndpoint, SessionAWSCredentials credentials) { try { var snsClient = new AmazonSimpleNotificationServiceClient(credentials, regionEndpoint); snsClient.ListTopics(new ListTopicsRequest()); return(true); } catch { return(false); } }
private bool TopicExists() { var exists = false; var response = _snsClient.ListTopics(); var matchString = string.Format(":{0}", TopicName); var matches = response.Topics.Where(x => x.TopicArn.EndsWith(matchString)); if (matches.Count() == 1) { exists = true; TopicArn = matches.ElementAt(0).TopicArn; } return(exists); }
public void ListTopics() { ListTopicsRequest request = new ListTopicsRequest(); var response = client.ListTopics(request); if (response.HttpStatusCode == System.Net.HttpStatusCode.OK) { foreach (var item in response.Topics) { Console.WriteLine(item.TopicArn); } } //Console.ReadLine(); }
public void ListTopics() { ListTopicsRequest request = new ListTopicsRequest { }; var response = client.ListTopics(request); if (response.HttpStatusCode.IsSuccess()) { foreach (var topic in response.Topics) { Console.WriteLine(topic.TopicArn); } } }
private bool IsTopicExists(AmazonSimpleNotificationServiceClient client, string Topic, out string TopicArn) { ListTopicsRequest lstTopicRequest = new ListTopicsRequest(); ListTopicsResponse lstTopicResponse = client.ListTopics(lstTopicRequest); ListTopicsResult lstTopicResult = lstTopicResponse.ListTopicsResult; List <Topic> TopicsList = lstTopicResult.Topics; TopicArn = string.Empty; bool IsTopicExists = TopicsList.Exists(x => x.TopicArn.Split(':')[x.TopicArn.Split(':').Count() - 1] == Topic); if (IsTopicExists) { string topicarn = TopicsList.Where(x => x.IsSetTopicArn() & x.TopicArn.Split(':')[x.TopicArn.Split(':').Count() - 1] == Topic).Select(s => s.TopicArn).First(); TopicArn = topicarn; } return(IsTopicExists); }
private static void ListSNSTopics(AmazonSimpleNotificationServiceClient sns) { // List all topics try { Console.WriteLine(); Console.WriteLine("Retrieving all topics..."); var listTopicsRequest = new ListTopicsRequest(); ListTopicsResponse listTopicsResponse; do { listTopicsResponse = sns.ListTopics(listTopicsRequest); foreach (var topic in listTopicsResponse.Topics) { Console.WriteLine(" Topic: {0}", topic.TopicArn); // Get topic attributes var topicAttributes = sns.GetTopicAttributes(new GetTopicAttributesRequest { TopicArn = topic.TopicArn }).Attributes; if (topicAttributes.Count > 0) { Console.WriteLine(" Topic attributes"); foreach (var topicAttribute in topicAttributes) { Console.WriteLine(" -{0} : {1}", topicAttribute.Key, topicAttribute.Value); } } Console.WriteLine(); } listTopicsRequest.NextToken = listTopicsResponse.NextToken; } while (listTopicsResponse.NextToken != null); } catch (AmazonSimpleNotificationServiceException ex) { Console.WriteLine("Caught Exception: " + ex.Message); Console.WriteLine("Response Status Code: " + ex.StatusCode); Console.WriteLine("Error Code: " + ex.ErrorCode); Console.WriteLine("Error Type: " + ex.ErrorType); Console.WriteLine("Request ID: " + ex.RequestId); } Console.ReadLine(); }
public static void SNSListTopics() { #region SNSListTopics var snsClient = new AmazonSimpleNotificationServiceClient(); var request = new ListTopicsRequest(); var response = new ListTopicsResponse(); do { response = snsClient.ListTopics(request); foreach (var topic in response.Topics) { Console.WriteLine("Topic: {0}", topic.TopicArn); var attrs = snsClient.GetTopicAttributes( new GetTopicAttributesRequest { TopicArn = topic.TopicArn }).Attributes; if (attrs.Count > 0) { foreach (var attr in attrs) { Console.WriteLine(" -{0} : {1}", attr.Key, attr.Value); } } Console.WriteLine(); } request.NextToken = response.NextToken; } while (!string.IsNullOrEmpty(response.NextToken)); #endregion Console.ReadLine(); }
public static void Main(string[] args) { var sns = new AmazonSimpleNotificationServiceClient(); string emailAddress = string.Empty; while (string.IsNullOrEmpty(emailAddress)) { Console.Write("Please enter an email address to use: "); emailAddress = Console.ReadLine(); } try { // Create topic Console.WriteLine("Creating topic..."); var topicArn = sns.CreateTopic(new CreateTopicRequest { Name = "SampleSNSTopic" }).TopicArn; // Set display name to a friendly value Console.WriteLine(); Console.WriteLine("Setting topic attributes..."); sns.SetTopicAttributes(new SetTopicAttributesRequest { TopicArn = topicArn, AttributeName = "DisplayName", AttributeValue = "Sample Notifications" }); // List all topics Console.WriteLine(); Console.WriteLine("Retrieving all topics..."); var listTopicsRequest = new ListTopicsRequest(); ListTopicsResponse listTopicsResponse; do { listTopicsResponse = sns.ListTopics(listTopicsRequest); foreach (var topic in listTopicsResponse.Topics) { Console.WriteLine(" Topic: {0}", topic.TopicArn); // Get topic attributes var topicAttributes = sns.GetTopicAttributes(new GetTopicAttributesRequest { TopicArn = topic.TopicArn }).Attributes; if (topicAttributes.Count > 0) { Console.WriteLine(" Topic attributes"); foreach (var topicAttribute in topicAttributes) { Console.WriteLine(" -{0} : {1}", topicAttribute.Key, topicAttribute.Value); } } Console.WriteLine(); } listTopicsRequest.NextToken = listTopicsResponse.NextToken; } while (listTopicsResponse.NextToken != null); // Subscribe an endpoint - in this case, an email address Console.WriteLine(); Console.WriteLine("Subscribing email address {0} to topic...", emailAddress); sns.Subscribe(new SubscribeRequest { TopicArn = topicArn, Protocol = "email", Endpoint = emailAddress }); // When using email, recipient must confirm subscription Console.WriteLine(); Console.WriteLine("Please check your email and press enter when you are subscribed..."); Console.ReadLine(); // Publish message Console.WriteLine(); Console.WriteLine("Publishing message to topic..."); sns.Publish(new PublishRequest { Subject = "Test", Message = "Testing testing 1 2 3", TopicArn = topicArn }); // Verify email receieved Console.WriteLine(); Console.WriteLine("Please check your email and press enter when you receive the message..."); Console.ReadLine(); // Delete topic Console.WriteLine(); Console.WriteLine("Deleting topic..."); sns.DeleteTopic(new DeleteTopicRequest { TopicArn = topicArn }); } catch (AmazonSimpleNotificationServiceException ex) { Console.WriteLine("Caught Exception: " + ex.Message); Console.WriteLine("Response Status Code: " + ex.StatusCode); Console.WriteLine("Error Code: " + ex.ErrorCode); Console.WriteLine("Error Type: " + ex.ErrorType); Console.WriteLine("Request ID: " + ex.RequestId); } Console.WriteLine(); Console.WriteLine("Press enter to exit..."); Console.ReadLine(); }
public static void Main(string[] args) { var sns = new AmazonSimpleNotificationServiceClient(); string emailAddress = string.Empty; var topicArn = "arn:aws:sns:us-east-1:546163609422:OrdersTopic"; while (string.IsNullOrEmpty(emailAddress)) { Console.Write("Please enter an email address to use: "); emailAddress = Console.ReadLine(); } try { // Create topic //Console.WriteLine("Creating topic..."); //var topicArn = sns.CreateTopic(new CreateTopicRequest //{ // Name = "SampleSNSTopic" //}).TopicArn; //// Set display name to a friendly value //Console.WriteLine(); //Console.WriteLine("Setting topic attributes..."); //sns.SetTopicAttributes(new SetTopicAttributesRequest //{ // TopicArn = topicArn, // AttributeName = "DisplayName", // AttributeValue = "Sample Notifications" //}); // List all topics Console.WriteLine(); Console.WriteLine("Retrieving all topics..."); var listTopicsRequest = new ListTopicsRequest(); ListTopicsResponse listTopicsResponse; do { listTopicsResponse = sns.ListTopics(listTopicsRequest); foreach (var topic in listTopicsResponse.Topics) { Console.WriteLine(" Topic: {0}", topic.TopicArn); // Get topic attributes var topicAttributes = sns.GetTopicAttributes(new GetTopicAttributesRequest { TopicArn = topic.TopicArn }).Attributes; if (topicAttributes.Count > 0) { Console.WriteLine(" Topic attributes"); foreach (var topicAttribute in topicAttributes) { Console.WriteLine(" -{0} : {1}", topicAttribute.Key, topicAttribute.Value); } } Console.WriteLine(); } listTopicsRequest.NextToken = listTopicsResponse.NextToken; } while (listTopicsResponse.NextToken != null); //// Subscribe an endpoint - in this case, an email address //Console.WriteLine(); //Console.WriteLine("Subscribing email address {0} to topic...", emailAddress); //sns.Subscribe(new SubscribeRequest //{ // TopicArn = topicArn, // Protocol = "email", // Endpoint = emailAddress //}); //// When using email, recipient must confirm subscription //Console.WriteLine(); //Console.WriteLine("Please check your email and press enter when you are subscribed..."); //Console.ReadLine(); // Publish message Orders ord = new Orders(); ShipToAddress st = new ShipToAddress(); st.Addr1 = "testAddr1"; st.Addr2 = "testAddr2"; st.City = "MyCity"; st.Zip = "00000"; ord.OrderId = "12345"; ord.OrderLocation = "Aurora"; ord.OrderQty = "100"; ord.OrderDate = "10222019"; ord.ShiptoAdr = st; string strJason = JsonConvert.SerializeObject(ord); Console.WriteLine(); Console.WriteLine("Publishing message to topic..."); sns.Publish(new PublishRequest { Subject = "Test", Message = strJason, MessageStructure = strJason, TopicArn = topicArn }); // Verify email receieved Console.WriteLine(); Console.WriteLine("Please check your email and press enter when you receive the message..."); Console.ReadLine(); //// Delete topic //Console.WriteLine(); //Console.WriteLine("Deleting topic..."); //sns.DeleteTopic(new DeleteTopicRequest //{ // TopicArn = topicArn //}); } catch (AmazonSimpleNotificationServiceException ex) { Console.WriteLine("Caught Exception: " + ex.Message); Console.WriteLine("Response Status Code: " + ex.StatusCode); Console.WriteLine("Error Code: " + ex.ErrorCode); Console.WriteLine("Error Type: " + ex.ErrorType); Console.WriteLine("Request ID: " + ex.RequestId); } Console.WriteLine(); Console.WriteLine("Press enter to exit..."); Console.ReadLine(); }