I had to override ActionHandler.on_event in one of our projects:
@classmethod
def on_event(cls, event, context):
"""
Normalize API Gateway HTTP API v2 cookie handling before awsgi2 builds the WSGI environ.
HTTP API v2 may deliver browser cookies in event["cookies"] instead of headers["cookie"].
awsgi2/mu expects a Cookie header when constructing the Flask request environ; without it,
Flask sees an empty request.cookies on POSTs even though the browser sent the session
cookie. That breaks session-backed CSRF validation because the form token is posted but the
corresponding session token is missing. Reconstructing the Cookie header here keeps Flask
session handling and CSRF checks working behind API Gateway.
"""
if isinstance(event, dict) and 'rawPath' in event:
headers = event.setdefault('headers', {})
if event.get('cookies') and 'cookie' not in {k.lower() for k in headers}:
headers['cookie'] = '; '.join(event['cookies'])
return super().on_event(event, context)
I had to override
ActionHandler.on_eventin one of our projects: