Skip to content

Can't get the final response in a waiter if it is failed #2262

Description

@abrooksv

Describe the Feature

Expose the last response to the Exception thrown from waiters on failure

Is your Feature Request related to a problem?

Yes, in the cases where the payload of the response triggers a waiter failure, it is impossible to make a decision based on the failure.

I.e.

  1. Create change set that will be empty
  2. Use CFN waiter waitUntilChangeSetCreateComplete
  3. Waiter throws SdkClientException with `The SDK waiter transitions the waiter to be failed in the case of no changes in the change set.
  4. No way to determine the cause of the failure due to SdkResponse is not set in the SdkClientException.
    1. In other words, did the change set fail to be created due to bad template, or did it fail due to no changes. One should be terminal failure, the other treated as no-op and skipped by my code.

Proposed Solution

Change Waiter to have a WaiterException that extends SdkClientException. It should have the response that triggered the failure state attached, if possible (i.e. not a timeout)

Describe alternatives you've considered

Additional Context

// Copyright 2021 Amazon.com, Inc. or its affiliates. All Rights Reserved.
// SPDX-License-Identifier: Apache-2.0

import software.amazon.awssdk.services.cloudformation.CloudFormationClient;

public class Repro {
    public static void main(String[] args) {
        String template = "AWSTemplateFormatVersion: '2010-09-09'\n"
                          + "Resources:\n"
                          + "  LogGroup:\n"
                          + "    Type: AWS::Logs::LogGroup\n";

        String stackName = "SomeStack";
        String changeSetName = "SomeName";

        CloudFormationClient cfnClient = CloudFormationClient.create();
        cfnClient.createStack(builder -> builder.stackName(stackName).templateBody(template));

        cfnClient.waiter().waitUntilStackCreateComplete(builder -> builder.stackName(stackName));

        cfnClient.createChangeSet(builder -> builder.stackName(stackName).changeSetName(changeSetName).templateBody(template));
        System.out.println(cfnClient.waiter().waitUntilChangeSetCreateComplete(builder -> builder.stackName(stackName).changeSetName(changeSetName)));
    }
}

Value of responseOrException passed into software.amazon.awssdk.core.internal.waiters.WaiterExecutor#evaluate:

responseOrException = {Either@4177} 
 left = {Optional@4182} "Optional[DescribeChangeSetResponse(ChangeSetName=SomeName, ChangeSetId=arn:aws:cloudformation:us-west-2:****:changeSet/SomeName/e24d90df-272a-4aba-a2eb-6b948f97b2ba, StackId=arn:aws:cloudformation:us-west-2:****:stack/SomeStackName/3500f520-61a7-11eb-82f2-0a1b1472165f, StackName=SomeStackName, CreationTime=2021-01-28T20:27:45.233Z, ExecutionStatus=UNAVAILABLE, Status=FAILED, StatusReason=The submitted information didn't contain changes. Submit different information to create a change set., NotificationARNs=[], RollbackConfiguration=RollbackConfiguration(), Capabilities=[], Changes=[], IncludeNestedStacks=false)]"
 right = {Optional@4183} "Optional.empty"
  • I may be able to implement this feature request

Your Environment

  • AWS Java SDK version used:
  • JDK version used:
  • Operating System and version:

Metadata

Metadata

Assignees

No one assigned

    Labels

    feature-requestA feature should be added or improved.p1This is a high priority issue

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions