简体   繁体   中英

AWS v1 vs v2 API for listing APIs on AWS API Gateway return different data for the same API Gateway instance

I want list list APIs available on my AWS API Gateway instance using REST API. I tried:

I am using the same auth credentials for both calls.

Both respond with 200 OK.

  • v1 returns proper data with my APIs
  • v2 returns an empty response ( {"items": []} )
  • AWS-CLI v2 command aws apigateway get-rest-apis returns proper data

Any idea why v2 REST API returns empty response?

v1 api gateways and v2 api gateways are distinct resources in AWS. In v1 there are only REST API Gateways and in v2 there are two types: HTTP and WebSocket gateways. They can coexist but they are incompatible with each-other and have very different feature sets.

For an overview of the differences, see the comparison between the types of API gateway here: https://docs.aws.amazon.com/apigateway/latest/developerguide/http-api-vs-rest.html

But to more specifically answer your question, the response from https://apigateway.eu-central-1.amazonaws.com/v2/apis is empty because you do not have any v2 "HTTP" apis and "REST" apis do not exist in v2.

The reason you see them in the v2 cli is because the v2 cli tools support both through separate sub-commands. It's not the version of the cli that matters so much as which sub-command you use:

  • "HTTP" APIs are managed with apigatewayv2
  • "REST" APIs are created with apigateway .

So using the v2 AWS-CLI with the apigateway sub-command is still accessing v1 apigateway resources.

You need to use aws apigatewayv2 get-apis for the equivalent functionality when working with the "HTTP" API gateway resources.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM