//snippet-sourcedescription:[DeleteAccessKey.java demonstrates how to delete an access key from an IAM user.]
//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.delete_access_key.complete]
// snippet-start:[iam.java2.delete_access_key.import]
import software.amazon.awssdk.regions.Region;
import software.amazon.awssdk.services.iam.IamClient;
import software.amazon.awssdk.services.iam.model.DeleteAccessKeyRequest;
import software.amazon.awssdk.services.iam.model.DeleteAccessKeyResponse;
 
// snippet-end:[iam.java2.delete_access_key.import]
/**
 * Deletes an access key from an IAM user
 */
public class DeleteAccessKey {
    public static void main(String[] args) {

        final String USAGE =
            "To run this example, supply a username and access key id\n" +
            "Ex: DeleteAccessKey <username> <access-key-id>\n";

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

        String username = args[0];
        String access_key = args[1];

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

        DeleteAccessKeyRequest request = DeleteAccessKeyRequest.builder()
            .accessKeyId(access_key)
            .userName(username).build();

        DeleteAccessKeyResponse response = iam.deleteAccessKey(request); 
        // snippet-end:[iam.java2.delete_access_key.main]

        System.out.println("Successfully deleted access key " + access_key +
                " from user " + username);
    }
}

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

@@ -259,16 +259,26 @@
 cedate:%5B
+03/02/2020
 %5D%0D%0A//sni
@@ -301,10 +301,15 @@
 r:%5Bs
-oo
+cmacdon
 -aws
@@ -332,18 +332,8 @@
 ght 
-2010-2019 
 Amaz
@@ -1267,35 +1267,21 @@
 del.
-DeleteAccessKeyResponse;%0D%0A 
+IamException;
 %0D%0A//
@@ -1331,16 +1331,18 @@
 mport%5D%0D%0A
+%0D%0A
 /**%0D%0A * 
@@ -1508,16 +1508,20 @@
         
+    
 %22To run 
@@ -1572,24 +1572,36 @@
 ey id%5Cn%22 +%0D%0A
+            
             
@@ -1827,18 +1827,17 @@
 g access
-_k
+K
 ey = arg
@@ -1997,36 +1997,93 @@
 er()
-.region(region).build();%0D%0A%0D%0A
+%0D%0A                .region(region)%0D%0A                .build();%0D%0A%0D%0A        try %7B%0D%0A%0D%0A    
     
@@ -2165,16 +2165,20 @@
         
+    
 .accessK
@@ -2188,18 +2188,17 @@
 d(access
-_k
+K
 ey)%0D%0A   
@@ -2206,16 +2206,20 @@
         
+  
+  
 .userNam
@@ -2254,42 +2254,11 @@
     
-DeleteAccessKeyResponse response =
+   
  iam
@@ -2287,11 +2287,16 @@
 st);
- 
 %0D%0A
+%0D%0A    
     
@@ -2350,18 +2350,20 @@
 .main%5D%0D%0A
-%0D%0A
+    
         
@@ -2424,18 +2424,17 @@
 + access
-_k
+K
 ey +%0D%0A  
@@ -2474,16 +2474,163 @@
 rname);%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    %7D%0D%0A
@@ -2632,18 +2632,16 @@
   %7D%0D%0A%7D%0D%0A
-%0D%0A
 // snipp

Update DeleteAccessKey.java