Skip to content

SESEvent KeyError #208

Closed
Closed

Description

@rprentyaws

What were you trying to accomplish?

Expected Behavior

I am trying to process an SES event using Lambda powertools for python.

Current Behavior

Error using this snippet:

[ERROR] KeyError: 0
Traceback (most recent call last):
  File "/var/task/lambda_function.py", line 11, in lambda_handler
    common_headers = list(mail.common_headers)
  File "/opt/python/aws_lambda_powertools/utilities/data_classes/common.py", line 11, in __getitem__
    return self._data[key]

Possible Solution

Steps to Reproduce (for bugs)

  1. Use the code in this snippet with powertools
  2. Use a test event of SES email, or just process an inbound SES email as the trigger.
  3. Check CloudWatch logs.

Environment

  • Powertools version used: 1.7.0
  • Packaging format (Layers, PyPi): Layers
  • AWS Lambda function runtime: Python 3.4
  • Debugging logs

How to enable debug mode**

[ERROR] KeyError: 0
Traceback (most recent call last):
  File "/var/task/lambda_function.py", line 11, in lambda_handler
    common_headers = list(mail.common_headers)
  File "/opt/python/aws_lambda_powertools/utilities/data_classes/common.py", line 11, in __getitem__
    return self._data[key]

Activity

  1. added
    bugSomething isn't working
    triagePending triage from maintainers
    on Nov 17, 2020
  2. self-assigned this
    on Nov 19, 2020
  3. to-mc commented on Nov 19, 2020

    @to-mc
    Contributor

    This is a documentation error: common_headers is not an iterable, so the list() call fails. I'll submit a PR to fix this, but in the mean time this is the corrected example:

    from aws_lambda_powertools.utilities.data_classes import SESEvent
    
    def lambda_handler(event, context):
        event: SESEvent = SESEvent(event)
    
        # Multiple records can be delivered in a single event
        for record in event.records:
            mail = record.ses.mail
            common_headers = mail.common_headers
    
            do_something_with(common_headers.to, common_headers.subject)
    
  4. added
    documentationImprovements or additions to documentation
    pending-releaseFix or implementation already in dev waiting to be released
    and removed
    triagePending triage from maintainers
    bugSomething isn't working
    pending-releaseFix or implementation already in dev waiting to be released
    on Nov 20, 2020
  5. heitorlessa commented on Nov 27, 2020

    @heitorlessa
    Contributor

    Now available in the docs - closing it :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

documentationImprovements or additions to documentation

Type

No type

Projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions