Bug: Can'´t use APIGatewayRestResolver in AWS Lambda with runtime Python 3.11 #5093
Replies: 4 comments
|
Hey @Kedaqusa1604! Thanks for opening this discussion. I don't think this is something specific with Python 3.11 and
This line make me curious if you're not using Can you send me a minimal reproducible snippet of this code to test in my environment? Thanks |
|
Sure, this is the process that I used: Build a lambda layer with these requirements (for python3.11): boto3==1.34.158
pydantic==2.0.3
unidecode==1.3.7
pynamodb==6.0.1
aws-lambda-powertools==2.43.1Lambda function (with the layer already associated): from aws_lambda_powertools.event_handler import APIGatewayRestResolver
import json
app = APIGatewayRestResolver()
def lambda_handler(event, context):
# TODO implement
return {
'statusCode': 200,
'body': json.dumps('Hello from Lambda!')
}Test logs (from lambda console): Actually, I get this error only in Lambda (and the docker images), but when I try it in my environment (python 3.11.5) it does work as expected. |
|
Actually, it's my fault, I'm installing an old library that has that "dataclasses" as dependency and I didn't notice that... Thanks for your time and excuse me 😮💨 |
|
Hi @Kedaqusa1604! No need to apologize! We are here to help customers adopt Powertools and solve problems. Sometimes we have some bugs, but I'm glad this was just a library version issue. Ping us if you need any additional help. |

Uh oh!
There was an error while loading. Please reload this page.
Hi there, I'm having some issues when trying to use the api gateway resolver in aws lambda using python3.11 as the selected runtime.
Here's the log of the exception:
[ERROR] AttributeError: module 'typing' has no attribute '_ClassVar'
Traceback (most recent call last):
File "/var/lang/lib/python3.11/importlib/init.py", line 126, in import_module
return _bootstrap._gcd_import(name[level:], package, level)
File "", line 1204, in _gcd_import
File "", line 1176, in _find_and_load
File "", line 1147, in _find_and_load_unlocked
File "", line 690, in _load_unlocked
File "", line 940, in exec_module
File "", line 241, in _call_with_frames_removed
File "/var/task/function.py", line 3, in
from aws_lambda_powertools.event_handler import APIGatewayRestResolver
File "/opt/python/aws_lambda_powertools/event_handler/init.py", line 5, in
from aws_lambda_powertools.event_handler.api_gateway import (
File "/opt/python/aws_lambda_powertools/event_handler/api_gateway.py", line 50, in
from aws_lambda_powertools.event_handler.util import (
File "/opt/python/aws_lambda_powertools/event_handler/util.py", line 3, in
from aws_lambda_powertools.utilities.data_classes.shared_functions import get_header_value
File "/opt/python/aws_lambda_powertools/utilities/data_classes/init.py", line 27, in
from .kinesis_firehose_event import (
File "/opt/python/aws_lambda_powertools/utilities/data_classes/kinesis_firehose_event.py", line 13, in
@DataClass(repr=False, order=False, frozen=True)
File "/opt/python/dataclasses.py", line 950, in wrap
return _process_class(cls, init, repr, eq, order, unsafe_hash, frozen)
File "/opt/python/dataclasses.py", line 800, in _process_class
cls_fields = [_get_field(cls, name, type)
File "/opt/python/dataclasses.py", line 800, in
cls_fields = [_get_field(cls, name, type)
File "/opt/python/dataclasses.py", line 659, in _get_field
if (_is_classvar(a_type, typing)
File "/opt/python/dataclasses.py", line 550, in _is_classvar
return type(a_type) is typing._ClassVar
Thanks in advance for your help.
All reactions