Giter Club home page Giter Club logo

Comments (2)

bblommers avatar bblommers commented on August 25, 2024 1

Hi @juanitosvq, thanks for trying to fix this in Moto! That is quite odd behaviour from AWS - I would expect them to return a 400 here instead.

The dispatch-method uses the URL's supplied by botocore, and botocore seems to also always expect the api_id to have some value.

Instead of fighting the url-matcher, and challenging/changing all the assumptions that the dispatch-method makes, I would suggest adding a custom method to handle this use-case. It is an outlier - I don't think I've seen anything else like this from AWS - so I'm not opposed to having a custom handler to solve this.

diff --git a/moto/apigatewayv2/responses.py b/moto/apigatewayv2/responses.py
index 18d6b1b83..553b1b8e7 100644
--- a/moto/apigatewayv2/responses.py
+++ b/moto/apigatewayv2/responses.py
@@ -20,6 +20,9 @@ class ApiGatewayV2Response(BaseResponse):
         """Return backend instance specific for this region."""
         return apigatewayv2_backends[self.current_account][self.region]
 
+    def get_api_without_id(self, *args):
+        return 200, {}, "{}"
+
     def create_api(self) -> TYPE_RESPONSE:
         params = json.loads(self.body)
 
diff --git a/moto/apigatewayv2/urls.py b/moto/apigatewayv2/urls.py
index 72f4922d6..013550a8e 100644
--- a/moto/apigatewayv2/urls.py
+++ b/moto/apigatewayv2/urls.py
@@ -9,6 +9,7 @@ url_bases = [
 
 url_paths = {
     "{0}/v2/apis$": ApiGatewayV2Response.dispatch,
+    "{0}/v2/apis/$": ApiGatewayV2Response.get_api_without_id,
     "{0}/v2/apis/(?P<api_id>[^/]+)$": ApiGatewayV2Response.dispatch,
     "{0}/v2/apis/(?P<api_id>[^/]+)/authorizers$": ApiGatewayV2Response.dispatch,
     "{0}/v2/apis/(?P<api_id>[^/]+)/authorizers/(?P<authorizer_id>[^/]+)$": ApiGatewayV2Response.dispatch,

If you could just add a small comment inside the new method to explain this usecases this serves, that would minimize future head scratching. 🙂

Note that I haven't linted this yet, so make sure to run make lint at the end to make sure our CI is happy - see https://docs.getmoto.org/en/latest/docs/contributing/installation.html#installing-moto-locally

from moto.

juanitosvq avatar juanitosvq commented on August 25, 2024

Thanks for the feedback, @bblommers
PR opened: #7978

from moto.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.