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

ApiGateway::GetApiKeys not returning any items #398

Open
richardwfrancis opened this issue Feb 19, 2021 · 3 comments
Open

ApiGateway::GetApiKeys not returning any items #398

richardwfrancis opened this issue Feb 19, 2021 · 3 comments

Comments

@richardwfrancis
Copy link

Just reporting odd behaviour with ApiGateway::GetApiKeys

my $paws = Paws->new(config => {
  credentials => Paws::Credential::File->new(
    profile => 'default',
    credentials_file => 'myCredentialsFile',
  )
});

my $apigateway = $paws->service('ApiGateway', region => 'us-east-1');

my $searchKeys = $apigateway->GetApiKeys(
  IncludeValues => 1
);

use Data::Dumper;
print Dumper($searchKeys)."\n";

The above code returns:

$VAR1 = bless( {
                 '_request_id' => '9f1482dc-0751-4d2a-99b6-668007328560',
                 'Items' => []
               }, 'Paws::ApiGateway::ApiKeys' );

I had expected this to return all available API keys and values (there are 5 already present in the AWS console).

Note that I am able to create new API keys using Paws as expected (i.e. a new one is created in the AWS console) using:

  my $newKey = $apigateway->CreateApiKey(
    Description        => "myDescription",
    Enabled            => 1,
    GenerateDistinctId => 1,
    Name               => "myName",
    StageKeys          => [
      {
        RestApiId => 'myRestApiID',
        StageName => 'api'
      }
    ],
  );

However, GetApiKeys still doesn't return anything.

Also, equivalent Python code using boto3 pulls back all the keys as expected.

Any help would be appreciated.

@msven
Copy link

msven commented Mar 4, 2021

I just ran into a similar issue today with the GetRestApis method. After some troubleshooting I discovered that the amazon apigateway api was returning a Content-Type of 'application/hal+json' when called through Paws, while the awscli was getting 'application/json' returned.

If I set the header 'Accept: application/json' in the request then Paws worked as expected.

e.g.

use Paws::Net::LWPCaller;
use LWP::UserAgent;

my $ua = LWP::UserAgent->new;
$ua->add_handler(
    request_prepare => sub{
        my($request, $ua, $handler) = @_;
        
        $request->header( 'Accept' => 'application/json' );
    }
);
my $caller = Paws::Net::LWPCaller->new( ua => $ua );

my $paws = Paws->new( config => { caller => $caller } );

Searching through botocore I found this line https://github.com/boto/botocore/blob/1.20.21/botocore/handlers.py#L983, where they are explicitly setting the Accept header for apigateway calls.

Update: Changed botocore link to reference a specific tag in case the line numbers change in the future (was referencing the develop branch previously)

@richardwfrancis
Copy link
Author

richardwfrancis commented Mar 6, 2021

Thank you @msven , great detective work.

There may be another way to do it, but adding the following code after creating the ApiGateway service worked for me.

$apigateway->caller()->ua()->default_headers( {'Accept' => 'application/json'} );

This worked in my case because calling $apigateway->caller()->ua() told me the agent being used was of the class HTTP::Tiny. If other agents are used then there may be other ways to provide the request headers.

Hopefully this will help the Paws developer team to alter the relevant module and include the right request header.

@byterock
Copy link
Collaborator

byterock commented Mar 6, 2021

I will have to check but I think in one of my many many patches (not released) I found and fixed that one.
I will be getting back to PAWS this month sometime. I just have to do the .42 release then I will get back to squishing reported bugs

Cheers John

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

3 participants