Skip to content
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

KeyError: 'requestContext' #126

Closed
seanaye opened this issue Jun 3, 2020 · 1 comment
Closed

KeyError: 'requestContext' #126

seanaye opened this issue Jun 3, 2020 · 1 comment

Comments

@seanaye
Copy link

seanaye commented Jun 3, 2020

likely related to #95

I'm just getting started with serverless in a test application. Im using poetry as python package manager and serverless framework to deploy.

my handler

from mangum import Mangum
from starlette.applications import Starlette
from starlette.responses import PlainTextResponse
from starlette.routing import Route


async def homepage(request):
    response = PlainTextResponse("Hello, world!")

    return response


app = Starlette(debug=True, routes=[Route("/", homepage)])

handler = Mangum(app)

my serverless.yml

# serverless.yml

org: seanaye
app: my-first-app

service: graphql-test

provider:
  name: aws
  runtime: python3.8

functions:
  graphql:
    handler: lambda_test/handler.handler


plugins:
  - serverless-python-requirements

custom:
  pythonRequirements:
    dockerizePip: non-linux

I get

[ERROR] KeyError: 'requestContext'
Traceback (most recent call last):
  File "/var/task/serverless_sdk/__init__.py", line 134, in wrapped_handler
    return user_handler(event, context)
  File "/var/task/mangum/adapter.py", line 110, in __call__
    return self.handler(event, context)
  File "/var/task/mangum/adapter.py", line 130, in handler
    if "eventType" in event["requestContext"]:END RequestId: ef16f1bf-973f-4e9a-95d9-4f2d7af32c23

on every sls invoke -f graphql --log

@jordaneremieff
Copy link
Owner

This is expected behaviour.

The adapter requires the information in the event and request context to form the ASGI connection scope, or it will not be able to run the application. API Gateway is used to invoke the Lambda function with event data for the specific API type. One thing you might try is invoking the function with test JSON data, but you'll have to consult the Serverless Framework documentation for more details on how to do this.

I can suggest modifying your configuration to include an HTTP API, then when you run sls deploy you can open the endpoint URL in your browser:

# serverless.yml

org: seanaye
app: my-first-app

service: graphql-test

provider:
  name: aws
  runtime: python3.8

functions:
  graphql:
    - httpApi: '*'
    handler: lambda_test/handler.handler

plugins:
  - serverless-python-requirements

custom:
  pythonRequirements:
    dockerizePip: non-linux

Beyond this I can't provide very much more support on Serverless Framework configurations specifically and would have to direct you to https://stackoverflow.com/ or other forums.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants