Skip to content

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

Closed
@heitorlessa

Description

@heitorlessa

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"
    }
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't workingp1

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions