Skip to content

HTTP API non-$default stage includes stage in rawPath as a prefix #621

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

Closed
heitorlessa opened this issue Aug 19, 2021 · 6 comments
Closed
Labels
bug Something isn't working p1

Comments

@heitorlessa
Copy link
Contributor

heitorlessa commented Aug 19, 2021

What were you trying to accomplish?

Configure a resource (/payment) with method in HTTP API to work with Event Handler utility.

Expected Behavior

Route to match

Current Behavior

API Gateway event handler returns 404

Possible Solution

Strip the stage out in the event path if available.

Steps to Reproduce (for bugs)

  1. Create a HTTP API
  2. Create an integration with Lambda using payload v2
  3. Rename $default to default
  4. Invoke API
def test_api_gateway_v2():
    # GIVEN a Http API V2 proxy type event
    app = ApiGatewayResolver(proxy_type=ProxyEventType.APIGatewayProxyEventV2)

    @app.post("/my/path")
    def my_path() -> Response:
        assert isinstance(app.current_event, APIGatewayProxyEventV2)
        post_data = app.current_event.json_body
        return Response(200, content_types.TEXT_PLAIN, post_data["username"])

    # WHEN calling the event handler
	event = load_event("apiGatewayProxyV2Event.json")

    # Mimicks HTTP API injecting the stage
    event["rawPath"] = "/default/my/path"

    result = app(event, {})

    # THEN process event correctly
    # AND set the current_event type as APIGatewayProxyEventV2
    assert result["statusCode"] == 200
    assert result["headers"]["Content-Type"] == content_types.TEXT_PLAIN
    assert result["body"] == "tom"

Environment

  • Powertools version used: 1.19.0
  • Packaging format (Layers, PyPi): PyPi
  • AWS Lambda function runtime: Python 3.8
  • Debugging logs

How to enable debug mode**

{
    "routeKey": "ANY /payment/{invoice+}",
    "rawPath": "/default/payment/invoiceABC",
    "requestContext": {
        "domainName": "api.serverlessa.dev",
        "http": {
            "method": "GET",
            "path": "/default/payment/invoiceABC"
        },
        "routeKey": "ANY /payment/{invoice+}",
        "stage": "default"
    },
    "pathParameters": {
        "invoice": "invoiceABC"
    }
}
@heitorlessa heitorlessa added bug Something isn't working triage Pending triage from maintainers area/event_handlers and removed triage Pending triage from maintainers labels Aug 19, 2021
@heitorlessa
Copy link
Contributor Author

@michaelbrewer created the issue so we don't forget

@heitorlessa heitorlessa added p2 p1 and removed p2 labels Aug 19, 2021
@heitorlessa
Copy link
Contributor Author

actually I'm wrong here, routeKey has the METHOD + , not rawPath.

#579 (comment)

@heitorlessa
Copy link
Contributor Author

HTTP API v2 does seem to add the stage as part of rawPath tho according to the dumps above - I renamed the default stage from $default to default and it appears in the event, which it'll also lead to 404.

Need to test with additional stages and once again with $default.

{
    "routeKey": "ANY /payment/{invoice+}",
    "rawPath": "/default/payment/invoiceABC",
    "requestContext": {
        "domainName": "api.serverlessa.dev",
        "http": {
            "method": "GET",
            "path": "/default/payment/invoiceABC"
        },
        "routeKey": "ANY /payment/{invoice+}",
        "stage": "default"
    },
    "pathParameters": {
        "invoice": "invoiceABC"
    }
}

@heitorlessa heitorlessa changed the title HTTP API resources set with ANY method return 404 HTTP API resources with non-$default stage include stage in rawPath Aug 19, 2021
@heitorlessa
Copy link
Contributor Author

heitorlessa commented Aug 19, 2021

Yep, that's another piece we need to work on to strip the stage IF not $default in HTTP API payload, or else it'll fail routing too.

Brand new HTTP API using $default stage

{
    "routeKey": "GET /payment",
    "rawPath": "/payment",
    "requestContext": {
        "domainName": "api.serverlessa.dev",
        "http": {
            "method": "GET",
            "path": "/payment"
        },
        "routeKey": "GET /payment",
        "stage": "$default"
    }
}

cc @michaelbrewer

@heitorlessa heitorlessa changed the title HTTP API resources with non-$default stage include stage in rawPath HTTP API non-$default stage includes stage in rawPath as a prefix Aug 19, 2021
@heitorlessa
Copy link
Contributor Author

heitorlessa commented Aug 19, 2021

@michaelbrewer
I've exposed endpoints that you could use to more easily generate these events, so it only generates the exact format I've used in these dumps:

v2 payload

v1 payload

@heitorlessa
Copy link
Contributor Author

Coming in today's release.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working p1
Projects
None yet
Development

No branches or pull requests

1 participant