Bug: Python 3.10 :: SQSEvent :: AttributeError: 'dict' object has no attribute 'records'
Expected Behaviour
events.records can be used as the iterator over records.
Current Behaviour
AttributeError: 'dict' object has no attribute 'records'
Code snippet
from aws_lambda_powertools.utilities.data_classes.sqs_event import SQSEvent
from aws_lambda_powertools.utilities.typing import LambdaContext
def lambda_handler(sqs_event: SQSEvent, context: LambdaContext):
for record in event.records: # where event["Records"] does not fail.
pass
Possible Solution
No response
Steps to Reproduce
Try to access event.records as a property on an SQSEvent instance.
Powertools for AWS Lambda (Python) version
2.42.0
AWS Lambda function runtime
3.10
Packaging format used
Lambda Layers
Debugging logs
No response
Thanks for opening your first issue here! We'll come back to you as soon as we can. In the meantime, check out the #python channel on our Powertools for AWS Lambda Discord: Invite link
Hi @CloutKhan! Thanks for opening this issue. This is actually not a bug, what is happening here is because you are using SQSEvent in your function signature but you are not using the @event_source decorator, so we are not able to convert your dict to an object. Check if this works with the code below:
from aws_lambda_powertools.utilities.data_classes import event_source, SQSEvent
from aws_lambda_powertools.utilities.typing import LambdaContext
@event_source(data_class=SQSEvent)
def lambda_handler(event: SQSEvent, context: LambdaContext):
for record in event.records: # where event["Records"] does not fail.
pass
thanks
Please reopen this issue if you need any further support @CloutKhan!
Closing as not a bug.
⚠️COMMENT VISIBILITY WARNING⚠️
This issue is now closed. Please be mindful that future comments are hard for our team to see.
If you need more assistance, please either tag a team member or open a new issue that references this one.
If you wish to keep having a conversation with other community members under this issue feel free to do so.