Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

SESEvent KeyError #208

Closed
rprentyaws opened this issue Nov 17, 2020 · 2 comments
Closed

SESEvent KeyError #208

rprentyaws opened this issue Nov 17, 2020 · 2 comments
Assignees
Labels
documentation Improvements or additions to documentation

Comments

@rprentyaws
Copy link

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]
@rprentyaws rprentyaws added bug Something isn't working triage Pending triage from maintainers labels Nov 17, 2020
@to-mc to-mc self-assigned this Nov 19, 2020
@to-mc
Copy link
Contributor

to-mc commented Nov 19, 2020

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)

@heitorlessa heitorlessa added documentation Improvements or additions to documentation pending-release Fix or implementation already in dev waiting to be released and removed triage Pending triage from maintainers bug Something isn't working pending-release Fix or implementation already in dev waiting to be released labels Nov 20, 2020
@heitorlessa
Copy link
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
Labels
documentation Improvements or additions to documentation
Projects
None yet
Development

No branches or pull requests

3 participants