I’ve been using the serverless framework for some time now. With it I use the serverless wsgi to invoke a serverless flask application for handling my API. Recently I started a new project following the same pattern but this time the API has a cognito authorizer. When working with this I was having a hard time getting cognito to work unless I added the integration attribute as lambda
inside of the HTTP event.
functions:
api:
handler: wsgi_handler.handler
events:
- http:
path: /api
method: ANY
cors: true
integration: lambda
authorizer:
type: COGNITO_USER_POOLS
authorizerId:
Ref: ApiGatewayAuthorizer
- http:
path: /api/{proxy+}
method: ANY
cors: true
integration: lambda
authorizer:
type: COGNITO_USER_POOLS
authorizerId:
Ref: ApiGatewayAuthorizer
At that point I thought I was golden but I realized that really I was getting a new error message returned from The serverless_wsgi.py. Digging into this file what I have learned was that the path info that’s attached to the event seems to be different than what was expected. Resulting in the error message that kills the whole thing.
# If a user is using a custom domain on API Gateway, they may have a base
# path in their URL. This allows us to strip it out via an optional
# environment variable.
path_info = event[u"path"]
base_path = os.environ.get("API_GATEWAY_BASE_PATH")
if base_path:
script_name = "/" + base_path
if path_info.startswith(script_name): # ERROR HERE: 'dict' object has no attribute 'startswith'
path_info = path_info[len(script_name) :]
path info in this scenario is {‘proxy’: ‘devices’} instead of /path/to/resource
So my question to the room is that I’m curious if anyone has done this or if I’m on an edge case? Or have I just overlooked something? I’m not sure what information to provide but I am using a custom domain and base path. im not sure how to resolve this issue. i dont know if my mistake is that i added this integration attribute but the issue i was facing that before making that change is documented in this screenshot