Skip to content

feat(data-classes): fix SES date field typing and add missing fields #1025

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

Closed
michaelbrewer opened this issue Feb 13, 2022 · 10 comments
Closed
Labels
bug Something isn't working

Comments

@michaelbrewer
Copy link
Contributor

michaelbrewer commented Feb 13, 2022

What were you trying to accomplish?

Use SESEvent with S3

Expected Behavior

  • date field is set to a List[str] and not a str
  • All fields should be included in the data classes

Current Behavior

Missing fields needs to be accessed via keys directly

Possible Solution

Add missing fields to SESEvent data class

Steps to Reproduce (for bugs)

Parsing regular SES message:

{
  "Records": [
    {
      "eventVersion": "1.0",
      "ses": {
        "mail": {
          "commonHeaders": {
            "from": [
              "Amazon Web Services <[email protected]>"
            ],
            "to": [
              "[email protected]"
            ],
            "returnPath": "[email protected]",
            "messageId": "<[email protected]>",
            "date": "Mon, 5 Dec 2016 18:40:08 -0800",
            "subject": "Test Subject"
          },
          "source": "[email protected]",
          "timestamp": "1970-01-01T00:00:00.123Z",
          "destination": [
            "[email protected]"
          ],
          "headers": [
            {
              "name": "Return-Path",
              "value": "<[email protected]>"
            },
            {
              "name": "Received",
              "value": "from mx.amazon.com (mx.amazon.com [127.0.0.1]) by inbound-smtp.us-east-1.amazonaws.com with SMTP id 6n4thuhcbhpfiuf25gshf70rss364fuejrvmqko1 for [email protected]; Tue, 06 Dec 2016 02:40:10 +0000 (UTC)"
            },
            {
              "name": "DKIM-Signature",
              "value": "v=1; a=rsa-sha256; c=relaxed/relaxed; d=iatn.net; s=amazon; h=mime-version:from:date:message-id:subject:to; bh=chlJxa/vZ11+0O9lf4tKDM/CcPjup2nhhdITm+hSf3c=; b=SsoNPK0wX7umtWnw8pln3YSib+E09XO99d704QdSc1TR1HxM0OTti/UaFxVD4e5b0+okBqo3rgVeWgNZ0sWZEUhBaZwSL3kTd/nHkcPexeV0XZqEgms1vmbg75F6vlz9igWflO3GbXyTRBNMM0gUXKU/686hpVW6aryEIfM/rLY="
            },
            {
              "name": "MIME-Version",
              "value": "1.0"
            },
            {
              "name": "From",
              "value": "Amazon Web Services <[email protected]>"
            },
            {
              "name": "Date",
              "value": "Mon, 5 Dec 2016 18:40:08 -0800"
            },
            {
              "name": "Message-ID",
              "value": "<[email protected]>"
            },
            {
              "name": "Subject",
              "value": "Test Subject"
            },
            {
              "name": "To",
              "value": "[email protected]"
            },
            {
              "name": "Content-Type",
              "value": "multipart/alternative; boundary=94eb2c0742269658b10542f452a9"
            }
          ],
          "headersTruncated": false,
          "messageId": "6n4thuhcbhpfiuf25gshf70rss364fuejrvmqko1"
        },
        "receipt": {
          "recipients": [
            "[email protected]"
          ],
          "timestamp": "1970-01-01T00:00:00.123Z",
          "spamVerdict": {
            "status": "PASS"
          },
          "dkimVerdict": {
            "status": "PASS"
          },
          "dmarcVerdict": {
            "status": "PASS"
          },
          "dmarcPolicy": "reject",
          "processingTimeMillis": 574,
          "action": {
            "type": "Lambda",
            "invocationType": "Event",
            "functionArn": "arn:aws:lambda:us-east-1:000000000000:function:my-ses-lambda-function"
          },
          "spfVerdict": {
            "status": "PASS"
          },
          "virusVerdict": {
            "status": "PASS"
          }
        }
      },
      "eventSource": "aws:ses"
    }
  ]
}

Parse a test SES S3 event

{
  "Records": [
    {
      "eventVersion": "1.0",
      "ses": {
        "receipt": {
          "timestamp": "2015-09-11T20:32:33.936Z",
          "processingTimeMillis": 406,
          "recipients": [
            "[email protected]"
          ],
          "spamVerdict": {
            "status": "PASS"
          },
          "virusVerdict": {
            "status": "PASS"
          },
          "spfVerdict": {
            "status": "PASS"
          },
          "dkimVerdict": {
            "status": "PASS"
          },
          "dmarcVerdict": {
            "status": "PASS"
          },
          "dmarcPolicy": "reject",
          "action": {
            "type": "S3",
            "topicArn": "arn:aws:sns:us-east-1:012345678912:example-topic",
            "bucketName": "my-S3-bucket",
            "objectKey": "email"
          }
        },
        "mail": {
          "timestamp": "2015-09-11T20:32:33.936Z",
          "source": "0000014fbe1c09cf-7cb9f704-7531-4e53-89a1-5fa9744f5eb6-000000@amazonses.com",
          "messageId": "d6iitobk75ur44p8kdnnp7g2n800",
          "destination": [
            "[email protected]"
          ],
          "headersTruncated": false,
          "headers": [
            {
              "name": "Return-Path",
              "value": "<0000014fbe1c09cf-7cb9f704-7531-4e53-89a1-5fa9744f5eb6-000000@amazonses.com>"
            },
            {
              "name": "Received",
              "value": "from a9-183.smtp-out.amazonses.com (a9-183.smtp-out.amazonses.com [54.240.9.183]) by inbound-smtp.us-east-1.amazonaws.com with SMTP id d6iitobk75ur44p8kdnnp7g2n800 for [email protected]; Fri, 11 Sep 2015 20:32:33 +0000 (UTC)"
            },
            {
              "name": "DKIM-Signature",
              "value": "v=1; a=rsa-sha256; q=dns/txt; c=relaxed/simple; s=ug7nbtf4gccmlpwj322ax3p6ow6yfsug; d=amazonses.com; t=1442003552; h=From:To:Subject:MIME-Version:Content-Type:Content-Transfer-Encoding:Date:Message-ID:Feedback-ID; bh=DWr3IOmYWoXCA9ARqGC/UaODfghffiwFNRIb2Mckyt4=; b=p4ukUDSFqhqiub+zPR0DW1kp7oJZakrzupr6LBe6sUuvqpBkig56UzUwc29rFbJF hlX3Ov7DeYVNoN38stqwsF8ivcajXpQsXRC1cW9z8x875J041rClAjV7EGbLmudVpPX 4hHst1XPyX5wmgdHIhmUuh8oZKpVqGi6bHGzzf7g="
            },
            {
              "name": "From",
              "value": "[email protected]"
            },
            {
              "name": "To",
              "value": "[email protected]"
            },
            {
              "name": "Subject",
              "value": "Example subject"
            },
            {
              "name": "MIME-Version",
              "value": "1.0"
            },
            {
              "name": "Content-Type",
              "value": "text/plain; charset=UTF-8"
            },
            {
              "name": "Content-Transfer-Encoding",
              "value": "7bit"
            },
            {
              "name": "Date",
              "value": "Fri, 11 Sep 2015 20:32:32 +0000"
            },
            {
              "name": "Message-ID",
              "value": "<[email protected]>"
            },
            {
              "name": "X-SES-Outgoing",
              "value": "2015.09.11-54.240.9.183"
            },
            {
              "name": "Feedback-ID",
              "value": "1.us-east-1.Krv2FKpFdWV+KUYw3Qd6wcpPJ4Sv/pOPpEPSHn2u2o4=:AmazonSES"
            }
          ],
          "commonHeaders": {
            "returnPath": "0000014fbe1c09cf-7cb9f704-7531-4e53-89a1-5fa9744f5eb6-000000@amazonses.com",
            "from": [
              "[email protected]"
            ],
            "date": "Fri, 11 Sep 2015 20:32:32 +0000",
            "to": [
              "[email protected]"
            ],
            "messageId": "<[email protected]>",
            "subject": "Example subject"
          }
        }
      },
      "eventSource": "aws:ses"
    }
  ]
}

Environment

  • Powertools version used: 1.25
  • Packaging format (Layers, PyPi):
  • AWS Lambda function runtime:
  • Debugging logs
@michaelbrewer michaelbrewer added bug Something isn't working triage Pending triage from maintainers labels Feb 13, 2022
michaelbrewer added a commit to gyft/aws-lambda-powertools-python that referenced this issue Feb 13, 2022
Change:
- Add missing fields from SESMailCommonHeaders
- Fix date type to be a str
- Add missing docs for SESReceiptStatus status field
- Add missing topicArn
- Add missing fields for Bounce, S3 and WorkMail actions

close aws-powertools#1025
@michaelbrewer michaelbrewer changed the title feat(data-classes): Add missing fields from SES data class feat(data-classes): Add missing fields from SES data-class and incorrect typing Feb 15, 2022
@heitorlessa
Copy link
Contributor

@michaelbrewer @ran-isenberg I'm missing more information here - could you help me understand whether this is related to SES->Lambda, or a trigger to SES that then invokes Lambda with a slightly different invoke?

I appreciate the links but I'm trying to understand how you ran into this in the first place, so we can prioritize it accordingly.

We had a similar case with SNS->Lambda vs SNS->SQS->Lambda, so trying to figure out if this is a similar type of issue that we're proactively addressing vs an actual SES->Lambda that we didn't foresee previously.

Thanks a lot!

@michaelbrewer
Copy link
Contributor Author

@heitorlessa i guess my confusion is as to why this was also added to the official GoLang AWS lambda events library.

Are these actual payloads coming to AWS lambda

@michaelbrewer
Copy link
Contributor Author

@heitorlessa - i can split up the PR into the hotfix (typing), from the missing fields.

michaelbrewer added a commit to gyft/aws-lambda-powertools-python that referenced this issue Feb 27, 2022
Changes:
- Fix date type to be a str and not List[str]
- Add missing fields from SESMailCommonHeaders (bcc, cc, sender and replyTo)
- Add missing dkimVerdict field
- Add missing dmarcPolicy field
- Add missing topicArn field
- Add missing docs for SESReceiptStatus status field

related aws-powertools#1025
@michaelbrewer
Copy link
Contributor Author

I created a new PR with simplifies the fix to only what we need for our Lambda use cases.

@michaelbrewer michaelbrewer changed the title feat(data-classes): Add missing fields from SES data-class and incorrect typing feat(data-classes): fix SES date field typing and add missing fields Apr 6, 2022
sthulb pushed a commit that referenced this issue Apr 28, 2022
Changes:
- Fix date type to be a str and not List[str]
- Add missing fields from SESMailCommonHeaders (bcc, cc, sender and replyTo)
- Add missing dkimVerdict field
- Add missing dmarcPolicy field
- Add missing topicArn field
- Add missing docs for SESReceiptStatus status field

related #1025
@sthulb sthulb closed this as completed Apr 28, 2022
@michaelbrewer
Copy link
Contributor Author

@sthulb can you clarify what this is being closed? It is a runtime error.

@michaelbrewer
Copy link
Contributor Author

Ok I see that the related PR was merged. Thanks.

@sthulb
Copy link
Contributor

sthulb commented Apr 28, 2022

Yeah, figured it was polite to close the issue when it was resolved 😀

@michaelbrewer
Copy link
Contributor Author

Haha. I just assumed the issue was rejected.

@sthulb
Copy link
Contributor

sthulb commented Apr 28, 2022

Someone I give a little too.

@heitorlessa heitorlessa added pending-release Fix or implementation already in dev waiting to be released and removed triage Pending triage from maintainers labels Apr 29, 2022
@github-actions
Copy link
Contributor

This is now released under 1.25.10 version!

@github-actions github-actions bot removed the pending-release Fix or implementation already in dev waiting to be released label Apr 29, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

3 participants