powertools-lambda-python icon indicating copy to clipboard operation
powertools-lambda-python copied to clipboard

Bug: Python 3.10 :: SQSEvent :: AttributeError: 'dict' object has no attribute 'records'

Open CloutKhan opened this issue 1 year ago • 2 comments

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

CloutKhan avatar Aug 09 '24 00:08 CloutKhan

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

boring-cyborg[bot] avatar Aug 09 '24 00:08 boring-cyborg[bot]

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

leandrodamascena avatar Aug 09 '24 13:08 leandrodamascena

Please reopen this issue if you need any further support @CloutKhan!

Closing as not a bug.

leandrodamascena avatar Aug 11 '24 21:08 leandrodamascena

⚠️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.

github-actions[bot] avatar Aug 11 '24 21:08 github-actions[bot]