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

Feature request: Missing parser type for IoT Core events #5891

Closed
2 tasks done
basvandriel opened this issue Jan 21, 2025 · 8 comments · Fixed by #5892
Closed
2 tasks done

Feature request: Missing parser type for IoT Core events #5891

basvandriel opened this issue Jan 21, 2025 · 8 comments · Fixed by #5892
Assignees
Labels
feature-request feature request parser Parser (Pydantic) utility

Comments

@basvandriel
Copy link
Contributor

Use case

On AWS IoT, you can configure registry events, which send messages to MQTT topics on for example creation, updating or deletion of things.

This generates the underneath format.

{
    "eventType" : "THING_EVENT",
    "eventId" : "f5ae9b94-8b8e-4d8e-8c8f-b3266dd89853",
    "timestamp" : 1234567890123,
    "operation" : "CREATED|UPDATED|DELETED",
    "accountId" : "123456789012",
    "thingId" : "b604f69c-aa9a-4d4a-829e-c480e958a0b5",
    "thingName" : "MyThing",
    "versionNumber" : 1,
    "thingTypeName" : null,
    "attributes": {
                "attribute3": "value3",
                "attribute1": "value1",
                "attribute2": "value2"
    }
}

This can be useful when developing lambda functions getting triggered by these events.

@event_parser
def handle(event: IoTCRUDEvent, _: LambdaContext):
    ...

Solution/User Experience

Implement the AWSIoTCRUDEvent so it's typed.

Alternative solutions

Acknowledgment

@basvandriel basvandriel added feature-request feature request triage Pending triage from maintainers labels Jan 21, 2025
Copy link

boring-cyborg bot commented Jan 21, 2025

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

@dreamorosi
Copy link
Contributor

Hi @basvandriel, thank you for opening this issue.

As a rule of thumb, we have been adding models only for events that come from direct triggers of AWS Lambda functions.

If I understand the documentation correctly, these are events that are sent by AWS IoT Core to specific IoT Topics instead.

While I understand that you can create rules to make it so that events for these topics can end up triggering a Lambda function, I wonder if this type of event is more of an application-specific event rather than one that belongs to the library.

Before moving forward with the review of the implementation, I'd like us maintainers to decide a criteria for deciding when to include this kind of events. I'm saying this mainly because there are many service integrations with IoT Core, many of which generate specific kinds of event, and I don't know if we should add them all.

@dreamorosi dreamorosi removed the triage Pending triage from maintainers label Jan 21, 2025
@dreamorosi dreamorosi moved this from Triage to Ideas in Powertools for AWS Lambda (Python) Jan 21, 2025
@leandrodamascena
Copy link
Contributor

Hi @basvandriel! Thanks for opening this issue! I worked on a project using IoT Core a while ago and integrated it with SQS and DynamoDB as a topic target. I also added some Lambda as a target, but they were receiving generic events that have nothing in common.

I see some potential in adding support for IoT as Event Source and Parser because I see a lot of customers using IoT jobs and events in their workloads. I also see that events have several fields in common, which makes sense to have a generalist class for those fields and specialized subclasses for each event type, like: THING_EVENT, THING_TYPE_EVENT and others.

Could you tell me in your architecture how the message from the MQTT topic is being sent to AWS Lambda? I want to confirm some architectural patterns before we proceed with this.

@leandrodamascena leandrodamascena added the need-more-information Pending information to continue label Jan 23, 2025
@leandrodamascena leandrodamascena moved this from Ideas to Pending review in Powertools for AWS Lambda (Python) Jan 23, 2025
@leandrodamascena leandrodamascena moved this from Pending review to Pending customer in Powertools for AWS Lambda (Python) Jan 23, 2025
@basvandriel
Copy link
Contributor Author

Hi @leandrodamascena , in my case, I'm using an IOT Rule to trigger the Lambda. There I'm selecting the correct data from the MQTT topic.

@leandrodamascena
Copy link
Contributor

Hi @basvandriel! Thanks for sending me more information. We're going to move forward with this implementation, but we need to make some changes to this PR to add support for all event types. I see you added a generic way to capture all events on this page, but I think we can be more intentional and create classes for specific events like:

class IOTCoreEventsBase(BaseModel): # all the common fields here
  ...

class IOCoreEventsThingEvent(IOTCoreEventsBase): # Specific fields for `THING_EVENT`
  ...

class IOCoreEventsThingTypeEvent(IOTCoreEventsBase): # Specific fields for `THING_TYPE_EVENT`
  ...

We also need to add tests to make sure we can parse those events.

Please reach out if you have any questions and we can work together to merge this PR.

@leandrodamascena leandrodamascena removed the need-more-information Pending information to continue label Feb 8, 2025
@basvandriel
Copy link
Contributor Author

I'll pick this up ASAP

@leandrodamascena
Copy link
Contributor

I'll pick this up ASAP

Thanks a lot! Please let me know if you have any questions that I can help you!

Copy link
Contributor

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

@leandrodamascena leandrodamascena moved this from Coming soon to Shipped in Powertools for AWS Lambda (Python) Feb 25, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feature-request feature request parser Parser (Pydantic) utility
Projects
Status: Shipped
Development

Successfully merging a pull request may close this issue.

4 participants