Amazon Simple Notification Service를 사용하여 클라우드에서 알림 전송 - AWS SDK for .NET (V4)

버전 4(V4) AWS SDK for .NET 가 릴리스되었습니다.

변경 사항 해제 및 애플리케이션 마이그레이션에 대한 자세한 내용은 마이그레이션 주제를 참조하세요.

기계 번역으로 제공되는 번역입니다. 제공된 번역과 원본 영어의 내용이 상충하는 경우에는 영어 버전이 우선합니다.

Amazon Simple Notification Service를 사용하여 클라우드에서 알림 전송

참고

이 주제의 정보는 .NET Framework 및 AWS SDK for .NET 버전 3.3 이하를 기반으로 하는 프로젝트에만 해당됩니다.

는 애플리케이션, 최종 사용자 및 디바이스가 클라우드에서 즉시 알림을 보낼 수 있는 웹 서비스인 Amazon Simple Notification Service(Amazon SNS)를 AWS SDK for .NET 지원합니다. 자세한 내용은 Amazon SNS를 참조하십시오.

Amazon SNS 주제 나열

다음 예제는 Amazon SNS 주제, 각 주제에 대한 구독, 각 주제에 대한 속성을 나열하는 방법을 보여줍니다. 이 예제에서는 기본 AmazonSimpleNotificationServiceClient를 사용합니다.

// using Amazon.SimpleNotificationService; // using Amazon.SimpleNotificationService.Model; var client = new AmazonSimpleNotificationServiceClient(); var request = new ListTopicsRequest(); var response = new ListTopicsResponse(); do { response = client.ListTopics(request); foreach (var topic in response.Topics) { Console.WriteLine("Topic: {0}", topic.TopicArn); var subs = client.ListSubscriptionsByTopic( new ListSubscriptionsByTopicRequest { TopicArn = topic.TopicArn }); var ss = subs.Subscriptions; if (ss.Any()) { Console.WriteLine(" Subscriptions:"); foreach (var sub in ss) { Console.WriteLine(" {0}", sub.SubscriptionArn); } } var attrs = client.GetTopicAttributes( new GetTopicAttributesRequest { TopicArn = topic.TopicArn }).Attributes; if (attrs.Any()) { Console.WriteLine(" Attributes:"); foreach (var attr in attrs) { Console.WriteLine(" {0} = {1}", attr.Key, attr.Value); } } Console.WriteLine(); } request.NextToken = response.NextToken; } while (!string.IsNullOrEmpty(response.NextToken));

Amazon SNS 주제로 메시지 전송

다음 예제는 메시지를 Amazon SNS 주제로 전송하는 방법을 보여줍니다. 이 예제에서는 하나의 인수(Amazon SNS 주제의 ARN)가 필요합니다.

using System; using System.Linq; using System.Threading.Tasks; using Amazon; using Amazon.SimpleNotificationService; using Amazon.SimpleNotificationService.Model; namespace SnsSendMessage { class Program { static void Main(string[] args) { /* Topic ARNs must be in the correct format: * arn:aws:sns:REGION:ACCOUNT_ID:NAME * * where: * REGION is the region in which the topic is created, such as us-west-2 * ACCOUNT_ID is your (typically) 12-character account ID * NAME is the name of the topic */ string topicArn = args[0]; string message = "Hello at " + DateTime.Now.ToShortTimeString(); var client = new AmazonSimpleNotificationServiceClient(region: Amazon.RegionEndpoint.USWest2); var request = new PublishRequest { Message = message, TopicArn = topicArn }; try { var response = client.Publish(request); Console.WriteLine("Message sent to topic:"); Console.WriteLine(message); } catch (Exception ex) { Console.WriteLine("Caught exception publishing request:"); Console.WriteLine(ex.Message); } } } }

GitHub의 명령줄에서 예제를 빌드하고 실행하는 방법에 대한 정보를 비롯한 전체 예제를 참조하십시오.

전화 번호로 SMS 메시지 전송

다음 예제는 SMS 메시지를 전화 번호로 전송하는 방법을 보여줍니다. 이 예제에서는 하나의 인수(전화 번호)가 필요합니다. 전화 번호는 주석에 설명된 두 가지 형식 중 하나여야 합니다.

using System; using System.Linq; using System.Threading.Tasks; using Amazon; using Amazon.SimpleNotificationService; using Amazon.SimpleNotificationService.Model; namespace SnsPublish { class Program { static void Main(string[] args) { // US phone numbers must be in the correct format: // +1 (nnn) nnn-nnnn OR +1nnnnnnnnnn string number = args[0]; string message = "Hello at " + DateTime.Now.ToShortTimeString(); var client = new AmazonSimpleNotificationServiceClient(region: Amazon.RegionEndpoint.USWest2); var request = new PublishRequest { Message = message, PhoneNumber = number }; try { var response = client.Publish(request); Console.WriteLine("Message sent to " + number + ":"); Console.WriteLine(message); } catch (Exception ex) { Console.WriteLine("Caught exception publishing request:"); Console.WriteLine(ex.Message); } } } }

GitHub의 명령줄에서 예제를 빌드하고 실행하는 방법에 대한 정보를 비롯한 전체 예제를 참조하십시오.