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

Struggling to make API Gateway call #458

Closed
cliff-wakefield-acurus opened this issue Jul 28, 2021 · 6 comments
Closed

Struggling to make API Gateway call #458

cliff-wakefield-acurus opened this issue Jul 28, 2021 · 6 comments

Comments

@cliff-wakefield-acurus
Copy link

Just trying to write a simple console app to call API gateway using IAM authentication pulled from the IAM role associated with the EC2 instance the code is running on.

But I can't even get the code to compile, I must be missing something obvious but I have read the examples and cannot see what I am doing wrong. It's like .NET doesn't see the HttpClient() extensions your library provides.

I looked through the test folder and also Google'd for examples but came up empty.

We are using .NET Core 2.1 at present, but soon to be .NET Core 3.1

using System;
using System.Net.Http;
using System.Threading.Tasks;
using Amazon.Runtime;
using AwsSignatureVersion4;

namespace console
{
    class Program
    {
        static void Main(string[] args)
        {
          MainAsync().GetAwaiter().GetResult();
        }

      private static async Task MainAsync()
      {
        var credentials = new InstanceProfileAWSCredentials();
        var client = new HttpClient();
        client.DefaultRequestHeaders.Add("x-apigw-api-id","#####");
        var response = await client.GetAsync(
        "https://#####.execute-api.ap-southeast-2.vpce.amazonaws.com/Prod/api/values",
        regionName: "ap-southeast-2",
        serviceName: "execute-api",
        credentials: credentials);
      }
    }
}

NOTE: I removed the specifics of our environment.

Build error is

Program.cs(23,9): error CS1739: The best overload for 'GetAsync' does not have a parameter named 'regionName' [/home/ubuntu/code/console/console.csproj]

Any assistance would be greatly appreciated.

@github-actions
Copy link
Contributor

Hi there and welcome to this repository!

A maintainer will be with you shortly, but first and foremost I would like to thank you for taking the time to report this issue. Quality is of the highest priority for us, and we would never release anything with known defects. We aim to do our best but unfortunately you are here because you encountered something we didn't expect. Lets see if we can figure out what went wrong and provide a remedy for it.

@FantasticFiasco
Copy link
Owner

Hi @cliff-wakefield-acurus!

I think the only issue with your code is that you need to change

credentials: credentials);

into

credentials: credentials.GetCredentials());

I assume that everything at that point should build.

@FantasticFiasco
Copy link
Owner

Maybe there is a bug in the README.md, I'll have to verify.

@FantasticFiasco
Copy link
Owner

There wasn't a bug in README.md, but then again the code sample is showing how to use the immutable credentials, and not the credentials you are using that inherit from AWSCredentials. I've updated the documentation to illustrate the differences.

@cliff-wakefield-acurus
Copy link
Author

You were correct it was the credentials parameter after all that.

I now have the code working...

Thank you...

FantasticFiasco added a commit that referenced this issue Jul 30, 2021
Improve support for credentials inheriting from Amazon.Runtime.AWSCredentials.

Closes #458
@FantasticFiasco
Copy link
Owner

I've just released v2.0.0, and it has improved support for AWSCredentials.

Specific to your issue, you should now be able to pass your instance of InstanceProfileAWSCredentials to the GetAsync extension method without having to get the immutable credentials using credentials.GetCredentials().

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants