//snippet-sourcedescription:[UpdateAccessKey.java demonstrates how to update the status of an access key for an IAM user.]
//snippet-keyword:[SDK for Java 2.0]
//snippet-keyword:[Code Sample]
//snippet-service:[iam]
//snippet-sourcetype:[full-example]
//snippet-sourcedate:[03/02/2020]
//snippet-sourceauthor:[scmacdon-aws]
/*
 * Copyright 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.update_access_key.complete]
// snippet-start:[iam.java2.update_access_key.import]
import software.amazon.awssdk.services.iam.model.IamException;
import software.amazon.awssdk.services.iam.model.StatusType;
import software.amazon.awssdk.services.iam.model.UpdateAccessKeyRequest;
import software.amazon.awssdk.services.iam.model.UpdateAccessKeyResponse;
import software.amazon.awssdk.regions.Region;
import software.amazon.awssdk.services.iam.IamClient;
// snippet-end:[iam.java2.update_access_key.import]

/**
 * Updates the status of an IAM user's access key
 */
public class UpdateAccessKey {

    public static void main(String[] args) {

        final String USAGE =
                "To run this example, supply a username, access key id and status\n" +
                        "Ex: UpdateAccessKey <username> <access-key-id> <Activate|Inactive>\n";
        if (args.length != 3) {
            System.out.println(USAGE);
            System.exit(1);
       }

        String username = args[0];
        String accessId = args[1];
        String status = args[2];

       try {
            StatusType statusType;

            if (status.toLowerCase().equalsIgnoreCase("active")) {
                statusType = StatusType.ACTIVE;
            } else if (status.toLowerCase().equalsIgnoreCase("inactive")) {
                statusType = StatusType.INACTIVE;
            } else {
                statusType = StatusType.UNKNOWN_TO_SDK_VERSION;
            }

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

            UpdateAccessKeyRequest request = UpdateAccessKeyRequest.builder()
                .accessKeyId(accessId)
                .userName(username)
                .status(statusType)
                .build();

            UpdateAccessKeyResponse response = iam.updateAccessKey(request);
            // snippet-end:[iam.java2.update_access_key.main]

            System.out.printf(
                "Successfully updated status of access key %s to" +
                        "status %s for user %s", accessId, status, username);

        } catch (IamException e) {
            System.err.println(e.awsErrorDetails().errorMessage());
            System.exit(1);
        }
        System.out.println("Done");
    }
}
// snippet-end:[iam.java2.update_access_key.complete]

@@ -207,19 +207,23 @@
 ervice:%5B
-iam
+AWS IAM
 %5D%0D%0A//sni
@@ -947,63 +947,8 @@
 m;%0D%0A
-// snippet-start:%5Biam.java2.update_access_key.complete%5D
 %0D%0A//
@@ -1523,24 +1523,68 @@
 essKey %7B%0D%0A%0D%0A
+   private static StatusType statusType;%0D%0A%0D%0A
     public s
@@ -2067,53 +2067,312 @@
     
-try %7B%0D%0A            StatusType statusType;%0D%0A%0D%0A
+ Region region = Region.AWS_GLOBAL;%0D%0A        IamClient iam = IamClient.builder().region(region).build();%0D%0A       %7D%0D%0A%0D%0A        // snippet-start:%5Biam.java2.update_access_key.main%5D%0D%0A       public static void updateKey(IamClient iam, String username, String accessId, String status ) %7B%0D%0A%0D%0A          try %7B%0D%0A  
     
@@ -2427,32 +2427,34 @@
 e(%22active%22)) %7B%0D%0A
+  
                 
@@ -2494,24 +2494,26 @@
             
+  
 %7D else if (s
@@ -2573,32 +2573,34 @@
                 
+ 
+ 
 statusType = Sta
@@ -2626,24 +2626,26 @@
             
+  
 %7D else %7B%0D%0A  
@@ -2638,24 +2638,26 @@
   %7D else %7B%0D%0A
+  
             
@@ -2725,201 +2725,15 @@
     
-%7D%0D%0A%0D%0A            // snippet-start:%5Biam.java2.update_access_key.main%5D%0D%0A            Region region = Region.AWS_GLOBAL;%0D%0A            IamClient iam = IamClient.builder().region(region).build();%0D%0A%0D%0A
+  %7D%0D%0A  
     
@@ -3471,59 +3471,4 @@
 %0A%7D%0D%0A
-// snippet-end:%5Biam.java2.update_access_key.complete%5D%0D%0A

Update UpdateAccessKey.java