//snippet-sourcedescription:[GetPolicy.java demonstrates how to get the details for an IAM policy.]
//snippet-keyword:[SDK for Java 2.0]
//snippet-keyword:[Code Sample]
//snippet-service:[iam]
//snippet-sourcetype:[full-example]
//snippet-sourcedate:[]
//snippet-sourceauthor:[soo-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.
 */
package com.example.iam;
// snippet-start:[iam.java2.get_policy.complete]
// snippet-start:[iam.java2.get_policy.import]
import software.amazon.awssdk.services.iam.model.GetPolicyRequest;
import software.amazon.awssdk.services.iam.model.GetPolicyResponse;

import software.amazon.awssdk.regions.Region;
import software.amazon.awssdk.services.iam.IamClient;
 
// snippet-end:[iam.java2.get_policy.import]
/**
 * Gets an IAM policy's details
 */
public class GetPolicy {

    public static void main(String[] args) {

        final String USAGE =
            "To run this example, supply a policy arn\n" +
            "Ex: GetPolicy <policy-arn>\n";

        if (args.length != 1) {
            System.out.println(USAGE);
            System.exit(1);
        }

        String policy_arn = args[0];

        // snippet-start:[iam.java2.get_policy.main]
        Region region = Region.AWS_GLOBAL;
        IamClient iam = IamClient.builder().region(region).build();

        GetPolicyRequest request = GetPolicyRequest.builder()
            .policyArn(policy_arn).build();

        GetPolicyResponse response = iam.getPolicy(request);
        // snippet-end:[iam.java2.get_policy.main]

        System.out.format("Successfully retrieved policy %s",
                response.policy().policyName());
    }
}

// snippet-end:[iam.java2.get_policy.complete]

@@ -249,16 +249,26 @@
 cedate:%5B
+03/02/2020
 %5D%0D%0A//sni
@@ -291,10 +291,15 @@
 r:%5Bs
-oo
+cmacdon
 -aws
@@ -322,18 +322,8 @@
 ght 
-2010-2019 
 Amaz
@@ -1151,18 +1151,16 @@
 ponse;%0D%0A
-%0D%0A
 import s
@@ -1253,17 +1253,80 @@
 lient;%0D%0A
- 
+import software.amazon.awssdk.services.iam.model.IamException;%0D%0A
 %0D%0A// sni
@@ -1526,16 +1526,20 @@
         
+    
 %22To run 
@@ -1578,16 +1578,28 @@
 n%5Cn%22 +%0D%0A
+            
         
@@ -1633,25 +1633,24 @@
 arn%3E%5Cn%22;%0D%0A%0D%0A
- 
        if (a
@@ -1772,18 +1772,17 @@
 g policy
-_a
+A
 rn = arg
@@ -1951,32 +1951,53 @@
 on).build();%0D%0A%0D%0A
+        try %7B%0D%0A%0D%0A    
         GetPolic
@@ -2055,16 +2055,20 @@
         
+    
 .policyA
@@ -2080,10 +2080,9 @@
 licy
-_a
+A
 rn).
@@ -2093,32 +2093,36 @@
 d();%0D%0A%0D%0A        
+    
 GetPolicyRespons
@@ -2159,32 +2159,36 @@
 uest);%0D%0A        
+   
+ 
 // snippet-end:%5B
@@ -2213,24 +2213,28 @@
 cy.main%5D%0D%0A%0D%0A
+    
         Syst
@@ -2338,18 +2338,196 @@
 );%0D%0A
+%0D%0A
     
+    %7D catch (IamException e) %7B%0D%0A            System.err.println(e.awsErrorDetails().errorMessage());%0D%0A            System.exit(1);%0D%0A    %7D%0D%0A        System.out.println(%22Done%22);%0D%0A    
 %7D%0D%0A%7D
-%0D%0A
 %0D%0A//

Update GetPolicy.java