//snippet-sourcedescription:[GetTopicAttributes.java demonstrates how to retrieve the defaults for an AWS SNS Topic.]
//snippet-keyword:[Java]
//snippet-sourcesyntax:[java]
//snippet-keyword:[Code Sample]
//snippet-keyword:[Amazon Simple Notification Service]
//snippet-service:[sns]
//snippet-sourcetype:[full-example]
//snippet-sourcedate:[2019-07-20]
//snippet-sourceauthor:[jschwarzwalder AWS]
/*
 * Copyright 2010-2019 Amazon.com, Inc. or its affiliates. All Rights Reserved.
 *
 * Licensed under the Apache License, Version 2.0 (the "License").
 * You may not use this file except in compliance with the License.
 * A copy of the License is located at
 *
 *  http://aws.amazon.com/apache2.0
 *
 * or in the "license" file accompanying this file. This file is distributed
 * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
 * express or implied. See the License for the specific language governing
 * permissions and limitations under the License.
 */
//snippet-start:[sns.java2.GetTopicAttributes.complete]
package com.example.sns;

//snippet-start:[sns.java2.GetTopicAttributes.import]

import software.amazon.awssdk.regions.Region;
import software.amazon.awssdk.services.sns.SnsClient;
import software.amazon.awssdk.services.sns.model.GetTopicAttributesRequest;
import software.amazon.awssdk.services.sns.model.GetTopicAttributesResponse;
//snippet-end:[sns.java2.GetTopicAttributes.import]

public class GetTopicAttributes {
    public static void main(String[] args) {
        final String USAGE = "\n" +
                "GetTopicAttributes - get attributes for an sns topic\n" +
                "Usage: GetTopicAttributes <topicArn>\n\n" +
                "Where:\n" +
                "  topicArn - the arn of the topic to look up.\n\n";

        if (args.length < 1) {
            System.out.println(USAGE);
            System.exit(1);
        }
        //snippet-start:[sns.java2.GetTopicAttributes.main]
        String topicArn = args[0];

        System.out.println("Getting attributes for a topic with name: " + topicArn);

        SnsClient snsClient = SnsClient.builder().region(Region.US_EAST_1).build();

        GetTopicAttributesRequest request = GetTopicAttributesRequest.builder()
                .topicArn(topicArn)
                .build();

        GetTopicAttributesResponse result = snsClient.getTopicAttributes(request);

        System.out.println("\n\nStatus was " + result.sdkHttpResponse().statusCode() + "\n\nAttributes: \n\n" + result.attributes());
        //snippet-end:[sns.java2.GetTopicAttributes.main]
    }
}
//snippet-end:[sns.java2.GetTopicAttributes.complete]


@@ -375,22 +375,16 @@
 or:%5B
-j
 sc
-hwarzwalder
+macdon
  AWS
@@ -408,18 +408,18 @@
  2010-20
-19
+20
  Amazon.
@@ -1106,17 +1106,16 @@
 import%5D%0A
-%0A
 import s
@@ -1359,16 +1359,79 @@
 sponse;%0A
+import software.amazon.awssdk.services.sns.model.SnsException;%0A
 //snippe
@@ -1863,25 +1863,24 @@
 %0A           
- 
 System.out.p
@@ -1894,17 +1894,16 @@
 USAGE);%0A
- 
         
@@ -1931,16 +1931,17 @@
       %7D%0A
+%0A
         
@@ -2027,17 +2027,16 @@
 rgs%5B0%5D;%0A
-%0A
         
@@ -2109,24 +2109,61 @@
 topicArn);%0A%0A
+        // Create a SnsClient object%0A
         SnsC
@@ -2199,16 +2199,33 @@
 uilder()
+%0A                
 .region(
@@ -2238,15 +2238,32 @@
 .US_
+W
 E
-A
 ST_
-1)
+2)%0A                
 .bui
@@ -2261,32 +2261,50 @@
      .build();%0A%0A
+        try %7B%0A    
         GetTopic
@@ -2430,32 +2430,36 @@
 ild();%0A%0A        
+    
 GetTopicAttribut
@@ -2517,17 +2517,20 @@
 quest);%0A
-%0A
+    
         
@@ -2654,16 +2654,158 @@
 utes());
+%0A%0A        %7D catch (SnsException e) %7B%0A            System.err.println(e.awsErrorDetails().errorMessage());%0A            System.exit(1);%0A        %7D
 %0A       
@@ -2917,9 +2917,8 @@
 mplete%5D%0A
-%0A

Update GetTopicAttributes.java