8000 Bug: Router context not being available when using AppSync with async resolvers · Issue #5290 · aws-powertools/powertools-lambda-python · GitHub
[go: up one dir, main page]

Skip to content
Bug: Router context not being available when using AppSync with async resolvers #5290
Closed
@bjorger

Description

@bjorger

Expected Behaviour

When accessing the router.context in a resolver, with async resolvers, it should not be an empty dict, but much rather expose the context injected with app.append_context

Current Behaviour

When using router.context in async resolvers, the router.context is an empty dict

Code snippet

def lambda_handler(event, context):
    token = extract_auth_token_from_event(event)
    logger.info("token", extra={"token": token})
    app.append_context(
        isAdmin=True,
    )
    result = app.resolve(event, context)

    return asyncio.run(result)

@router.resolver(type_name="Mutation", field_name="addPet")
async def addPet(pet: dict):
    logger.info("Handling add pet mutation")
    logger.info("Context", extra={"resolver_context": router.context}) // this shows that router.context is an empty dict.
    
    return { "name": "Peter", "type": "Cat" }

Possible Solution

No response

Steps to Reproduce

Just plug in the lambda_handler and mutation I attached above, deploy it and run the mutation via the AppSync console

Powertools for AWS Lambda (Python) version

latest

AWS Lambda function runtime

3.8

Packaging format used

Lambda Layers

Debugging logs

No response

Metadata

Metadata

Labels

bugSomething isn't workinghelp wantedCould use a second pair of eyes/hands

Type

Projects

Status

Shipped

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions

    0