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

No way to execute dry-run EC2 operations (e.g. StartInstances) #3595

Open
1 task
sstragier-prosperops opened this issue Dec 31, 2024 · 2 comments
Open
1 task
Labels
bug This issue is a bug. module/sdk-custom p2 This is a standard priority issue queued s Effort estimation: small

Comments

@sstragier-prosperops
Copy link

Describe the bug

There doesn't appear to be a way to execute dry-run EC2 operations (e.g. StartInstances) since DryRun isn't a parameter of the StartInstancesRequest and the DryRun method in AmazonEC2Client (which isn't exposed on the interface, #3594) doesn't work because it appears to be looking for the old non-async request methods which are no longer public.

Regression Issue

  • Select this option if this issue appears to be a regression.

Expected Behavior

I should be able to run EC2 operations that support a DryRun flag (e.g. StartInstances, StopInstances)

Current Behavior

I am not able to run EC2 operations with the DryRun flag to check access to these operations

Reproduction Steps

var ec2Client = new AmazonEC2Client();
var response = ec2Client.DryRun(new StartInstances { InstanceIds = new() { "i-xxxxxxx" } });
// response.Error = "Unrecognized request"

Possible Solution

No response

Additional Information/Context

No response

AWS .NET SDK and/or Package version used

AWSSDK.EC2 3.7.405.7

Targeted .NET Platform

.NET 6

Operating System and version

Windows 10

@sstragier-prosperops sstragier-prosperops added bug This issue is a bug. needs-triage This issue or PR still needs to be triaged. labels Dec 31, 2024
@ashishdhingra ashishdhingra self-assigned this Dec 31, 2024
@ashishdhingra ashishdhingra added module/sdk-custom investigating This issue is being investigated and/or work is in progress to resolve the issue. p2 This is a standard priority issue and removed needs-triage This issue or PR still needs to be triaged. labels Dec 31, 2024
@ashishdhingra
Copy link
Contributor

ashishdhingra commented Dec 31, 2024

@sstragier-prosperops Good afternoon. Thanks for opening the issue. The reason why IAmazonEC2 interface does not have access to the DryRun() method defined in AmazonEC2Client is because:

  • IAmazonEC2 (taking netstandard target as an example) interface is auto-generated from ec2 service model (notice that it's in Generated folder).
  • AmazonEC2Client.DryRun() is more kind of custom extension method (notice it as defined under Custom folder).

Your analysis appears to be correct. The logic here is checking that return type ends with Response. But the return type for public methods starts with Task< and ends with Response> (e.g. Task<StartInstancesResponse> for StartInstancesAsync()) for projects targeting netstandard (BCL targets have define public interface for the methods where return type ends with Response and should work fine).

To fix this issue, code here could have check based on conditional compilation symbols for different targets (we might also need to revisit other logic as well).

The SetDryRunParameterCallback is just setting the request parameter DryRun to true. The manual workaround would be to explicitly set DryRun property for the API operations you would like to invoke via AmazonEC2Client. (this is not applicable since request model doesn't expose boolean DryRun property due to it being excluded as part of ec2.customizations.json)

This issue needs review with team.

Thanks,
Ashish

@ashishdhingra ashishdhingra added needs-review xs Effort estimation: tiny s Effort estimation: small and removed investigating This issue is being investigated and/or work is in progress to resolve the issue. xs Effort estimation: tiny labels Dec 31, 2024
@sstragier-prosperops
Copy link
Author

sstragier-prosperops commented Jan 2, 2025

Thanks for the follow up. Yes, I've been able to workaround by using the request's BeforeRequestHandler to add the DryRun property to the request (similar to the code in AmazonEC2Client). However, it would be nice to have this functionality baked into the SDK.

public static void SetDryRun(this AmazonWebServiceRequest request)
{
    request.AddBeforeRequestHandler(SetDryRunParameterCallback);

    void SetDryRunParameterCallback(object sender, RequestEventArgs args)
    {
        var a = args as WebServiceRequestEventArgs ?? throw new InvalidOperationException("Expected WebServiceRequestEventArgs");
        a.ParameterCollection["DryRun"] = new StringParameterValue("true");

        // After the callback has been invoked, remove it
        request.RemoveBeforeRequestHandler(SetDryRunParameterCallback);
    }
}

@ashishdhingra ashishdhingra removed their assignment Jan 2, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug This issue is a bug. module/sdk-custom p2 This is a standard priority issue queued s Effort estimation: small
Projects
None yet
Development

No branches or pull requests

2 participants