Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

AWS API Gateway - Call GET Method with C# SDK

I have an API Gateway that uses IAM authorization. I have a C# application that I'm hoping to call the API with. I started with a GetMethodRequest but I don't see anyway to set the PathPart parameter.

var userId = _remoteCredentials.UserId;
var key = _remoteCredentials.Key;

var client = new AmazonAPIGatewayClient(userId, key, Amazon.RegionEndpoint.USEast2);
GetMethodRequest getMethodRequest = new GetMethodRequest();
getMethodRequest.HttpMethod = HttpMethod.Get.ToString();
getMethodRequest.ResourceId = "4abcde";
getMethodRequest.RestApiId = "aasfasdfs";

var task = Task.Run(async () => await client.GetMethodAsync(getMethodRequest).ConfigureAwait(false));

I was expecting something like the Test-AGInvokeMethod in the Powershell SDK which allows me to set the query string and the path.

$response = Test-AGInvokeMethod 
                   -RestApiId aasfasdfs
                   -ResourceId 4abcde
                   -HttpMethod GET 
                   -PathWithQueryString '/etl/upload_url'

Any help is greatly appreciated.

EDIT Below is something of a solution that I ended up using the AWS4RequestSigner is a library that I found on Github

var signer = new AWS4RequestSigner(userId, key);
var destinationUrl = string.Format("https://ad9vxabc123.execute-api.us-east-2.amazonaws.com/dev/etl/summary/latest?tms_id={0}&model_id={1}", _tmsId, _modelId);
var request = new HttpRequestMessage
{
    Method = HttpMethod.Get,
    RequestUri = new Uri(destinationUrl),
};

var signed = Task.Run(async () => await signer.Sign(request, "execute-api", "us-east-2").ConfigureAwait(false));
var signedResult = signed.Result;
like image 804
Black Dynamite Avatar asked Nov 23 '25 23:11

Black Dynamite


1 Answers

The AmazonAPIGatewayClient is for managing your API Gateway e.g. adding new stages or deleting API keys.

You're looking to invoke a method on your API Gateway, like Test-AGInvokeMethod does.

To invoke your API gateway, you need to call the deployed API endpoint using a HTTP client.

.NET's in-built HttpClient is a good start.

like image 129
Ermiya Eskandary Avatar answered Nov 26 '25 12:11

Ermiya Eskandary



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!