SetTopicAttributes() public method

Allows a topic owner to set an attribute of the topic to a new value.
/// Indicates that the user has been denied access to the requested resource. /// /// Indicates an internal service error. /// /// Indicates that a request parameter does not comply with the associated constraints. /// /// Indicates that the requested resource does not exist. ///
public SetTopicAttributes ( SetTopicAttributesRequest request ) : SetTopicAttributesResponse
request SetTopicAttributesRequest Container for the necessary parameters to execute the SetTopicAttributes service method.
return SetTopicAttributesResponse
Exemplo n.º 1
0
        /// <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);
            }
        }
Exemplo n.º 2
0
    public static void SNSCreateSubscribePublish()
    {
      #region SNSCreateSubscribePublish
      var snsClient = new AmazonSimpleNotificationServiceClient();

      var topicRequest = new CreateTopicRequest
      {
        Name = "CodingTestResults"
      };

      var topicResponse = snsClient.CreateTopic(topicRequest);

      var topicAttrRequest = new SetTopicAttributesRequest
      {
        TopicArn = topicResponse.TopicArn,
        AttributeName = "DisplayName",
        AttributeValue = "Coding Test Results"
      };

      snsClient.SetTopicAttributes(topicAttrRequest);

      snsClient.Subscribe(new SubscribeRequest
      {
        Endpoint = "*****@*****.**",
        Protocol = "email",
        TopicArn = topicResponse.TopicArn
      });

      // Wait for up to 2 minutes for the user to confirm the subscription.
      DateTime latest = DateTime.Now + TimeSpan.FromMinutes(2);

      while (DateTime.Now < latest)
      {
        var subsRequest = new ListSubscriptionsByTopicRequest
        {
          TopicArn = topicResponse.TopicArn
        };

        var subs = snsClient.ListSubscriptionsByTopic(subsRequest).Subscriptions;

        var sub = subs[0];

        if (!string.Equals(sub.SubscriptionArn,
          "PendingConfirmation", StringComparison.Ordinal))
        {
          break;
        }

        // Wait 15 seconds before trying again.
        System.Threading.Thread.Sleep(TimeSpan.FromSeconds(15));
      }

      snsClient.Publish(new PublishRequest
      {
        Subject = "Coding Test Results for " +
          DateTime.Today.ToShortDateString(),
        Message = "All of today's coding tests passed.",
        TopicArn = topicResponse.TopicArn
      });
      #endregion
    }