@@ -0,0 +1,2884 @@
+//snippet-sourcedescription:%5BDetachInstances.java removes one or more instances from the specified Auto Scaling group.%5D%0A//snippet-keyword:%5BAWS SDK for Java v2%5D%0A//snippet-keyword:%5BCode Sample%5D%0A//snippet-service:%5BAmazon EC2 Auto Scaling%5D%0A//snippet-sourcetype:%5Bfull-example%5D%0A//snippet-sourcedate:%5B05/05/2022%5D%0A%0A/*%0A   Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.%0A   SPDX-License-Identifier: Apache-2.0%0A*/%0A%0Apackage com.example.autoscaling;%0A%0A// snippet-start:%5Bautoscale.java2.detach.import%5D%0Aimport software.amazon.awssdk.auth.credentials.ProfileCredentialsProvider;%0Aimport software.amazon.awssdk.regions.Region;%0Aimport software.amazon.awssdk.services.autoscaling.AutoScalingClient;%0Aimport software.amazon.awssdk.services.autoscaling.model.AutoScalingException;%0Aimport software.amazon.awssdk.services.autoscaling.model.DetachInstancesRequest;%0A// snippet-end:%5Bautoscale.java2.detach.import%5D%0A%0A/**%0A * Before running this SDK for Java (v2) code example, set up your development environment, including your credentials.%0A *%0A * For more information, see the following documentation:%0A *%0A * https://docs.aws.amazon.com/sdk-for-java/latest/developer-guide/get-started.html%0A */%0Apublic class DetachInstances %7B%0A%0A    public static void main(String%5B%5D args) %7B%0A%0A        final String usage = %22%5Cn%22 +%0A                %22Usage:%5Cn%22 +%0A                %22    %3CgroupName%3E %3CinstanceId%3E%5Cn%5Cn%22 +%0A                %22Where:%5Cn%22 +%0A                %22    groupName - The name of the Auto Scaling group.%5Cn%22 +%0A                %22    instanceId - The instance Id value.%5Cn%22 ;%0A%0A        if (args.length != 2) %7B%0A            System.out.println(usage);%0A            System.exit(1);%0A        %7D%0A%0A        String groupName = args%5B0%5D;%0A        String instanceId = args%5B1%5D;%0A        AutoScalingClient autoScalingClient = AutoScalingClient.builder()%0A                .region(Region.US_EAST_1)%0A                .credentialsProvider(ProfileCredentialsProvider.create())%0A                .build();%0A%0A        detachInstance(autoScalingClient, groupName, instanceId);%0A        autoScalingClient.close();%0A    %7D%0A%0A    // snippet-start:%5Bautoscale.java2.detach.main%5D%0A    public static void detachInstance(AutoScalingClient autoScalingClient, String groupName, String instanceId) %7B%0A%0A        try %7B%0A            DetachInstancesRequest detachInstancesRequest = DetachInstancesRequest.builder()%0A                    .autoScalingGroupName(groupName)%0A                    .shouldDecrementDesiredCapacity(false)%0A                    .instanceIds(instanceId)%0A                    .build();%0A%0A            autoScalingClient.detachInstances(detachInstancesRequest);%0A            System.out.println(%22You have detached instance %22+instanceId +%22 from %22+groupName);%0A%0A        %7D catch (AutoScalingException e) %7B%0A            System.err.println(e.awsErrorDetails().errorMessage());%0A            System.exit(1);%0A        %7D%0A    %7D%0A    // snippet-end:%5Bautoscale.java2.detach.main%5D%0A%7D%0A

Create DetachInstances.java