Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

EC2 Dry-Runs #76

Closed
millems opened this issue Jul 20, 2017 · 3 comments
Closed

EC2 Dry-Runs #76

millems opened this issue Jul 20, 2017 · 3 comments
Labels
1.x Parity feature-request A feature should be added or improved. p2 This is a standard priority issue

Comments

@millems
Copy link
Contributor

millems commented Jul 20, 2017

In 1.11.x, customers can execute certain EC2 requests as a "dry-run" request. This adds a special header to tell EC2 to not actually execute the request.

Support for this feature should be added in 2.0.

@justnance justnance added feature-request A feature should be added or improved. and removed Feature Request labels Apr 19, 2019
@millems millems changed the title EC2 Dry-Run Support EC2 Dry-Runs Jul 8, 2019
@bgola-signalfx
Copy link

Bump. I think it should be a common feature of the SDK applicable to all requests. Otherwise it is difficult to check if we have all the required permissions to execute some task before actually starting the whole process.

@joviegas
Copy link
Contributor

After merging above PR , we can get the dry run status as below

Sync Client

        // Lets consider we want to find the dryRun Status for describeRegions API
        boolean dryRunComplete = isDryRunComplete(() -> ec2Client.describeRegions(r -> r.regionNames(Region.US_EAST_1.id()).dryRun(true)));

    // Write a generic Private API that takes in any EC2 Operation , make sure dryRun flag is set and extract the Error response
    private boolean isDryRunComplete(Supplier<Ec2Response> dryRunOp) {
        Ec2Response ec2Response = null;
        try {
            ec2Response = dryRunOp.get();
        } catch (Ec2Exception exception) {
            AwsErrorDetails awsErrorDetails = exception.awsErrorDetails();
            if ("AuthFailure".equals(awsErrorDetails.errorCode())) {
                return false;
            }
            if ("DryRunOperation".equals(awsErrorDetails.errorCode())) {
                return true;
            }
            throw exception;
        }
        throw new IllegalStateException("Unable to get dryRun status for ec2Response:  " + ec2Response);
    }

Async Client

        Boolean isDryRunComplete = asyncClient.describeRegions(r -> r.regionNames(Region.US_EAST_1.id())
                                                                     .dryRun(true))
                                              .handle((resp, e) -> isDryRunCompleted(e))
                                              .join();

    // Write a generic Private API that gets the DryRun status from the exception
    private static Boolean isDryRunCompleted(Throwable exceptionCaught) {
        if(exceptionCaught.getCause() instanceof Ec2Exception){
            Ec2Exception exception = (Ec2Exception) exceptionCaught.getCause();
            AwsErrorDetails awsErrorDetails = exception.awsErrorDetails();
            if ("AuthFailure".equals(awsErrorDetails.errorCode())) {
                return false;
            }
            if ("DryRunOperation".equals(awsErrorDetails.errorCode())) {
                return true;
            }
        }
        throw new IllegalStateException(exceptionCaught.getCause());
    }

Copy link

⚠️COMMENT VISIBILITY WARNING⚠️

Comments on closed issues are hard for our team to see.
If you need more assistance, please open a new issue that references this one.
If you wish to keep having a conversation with other community members under this issue feel free to do so.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
1.x Parity feature-request A feature should be added or improved. p2 This is a standard priority issue
Projects
None yet
Development

No branches or pull requests

5 participants