Closed
Description
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)
- Create a HTTP API
- Create an integration with Lambda using payload v2
- Rename
$default
todefault
- 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
{
"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"
}
}