Skip to content

Feature request: Event Source Data Classes for API Gateway WebSocket events #6161

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
2 tasks done
ericbn opened this issue Feb 25, 2025 · 6 comments · Fixed by #6287
Closed
2 tasks done

Feature request: Event Source Data Classes for API Gateway WebSocket events #6161

ericbn opened this issue Feb 25, 2025 · 6 comments · Fixed by #6287
Assignees
Labels
event_sources Event Source Data Class utility feature-request feature request

Comments

@ericbn
Copy link
Contributor

ericbn commented Feb 25, 2025

Use case

I see Pydantic models were added for API Gateway WebSocket events here:

Model name Description
APIGatewayWebSocketMessageEventModel Lambda Event Source payload for Amazon API Gateway WebSocket API message body
APIGatewayWebSocketConnectEventModel Lambda Event Source payload for Amazon API Gateway WebSocket API $connect message
APIGatewayWebSocketDisconnectEventModel Lambda Event Source payload for Amazon API Gateway WebSocket API $disconnect message

This is request to add the corresponding Event Source Data Classes.

Solution/User Experience

It would be used like below, as an example:

import requests
from aws_lambda_powertools.utilities.data_classes import (
    APIGatewayWebSocketMessageEvent,
    event_source,
)

session = requests.Session()

@event_source(data_class=APIGatewayWebSocketMessageEvent)
def lambda_handler(event: APIGatewayWebSocketMessageEvent, context):
    params = {
        "connection_id": event.request_context.connection_id,
        "data": event.json_body,
    }
    response = session.post("https://mydomain.com/myapi", data=params)
    if 400 <= response.status_code < 600:
        raise RuntimeError(response.text)
    return {"statusCode": 200}

Alternative solutions

I see other requests related to API Gateway WebSocket events, but they seem like different features: #1165, #5905

Acknowledgment

@leandrodamascena
Copy link
Contributor

Bem-vindo de volta @ericbn! Super nice see you here again!

Yes, it makes perfect sense to add these models to the event source as well. Do you want to submit a PR for this?

These other requests are more related to creating a Resolver for WebSocket APIs, but I'd like to explore more ideas before deciding on that.

@leandrodamascena leandrodamascena added event_sources Event Source Data Class utility and removed triage Pending triage from maintainers labels Feb 25, 2025
@ericbn
Copy link
Contributor Author

ericbn commented Feb 25, 2025

Oi @leandrodamascena. Thanks! I can help with a PR. It's just not something I already started working at.

@leandrodamascena
Copy link
Contributor

Oi @leandrodamascena. Thanks! I can help with a PR. It's just not something I already started working at.

No rush at all! Take your time and if you need any help with this PR, please let me know.

@leandrodamascena
Copy link
Contributor

Hi @ericbn! I'm not in a rush, but just adjusting our dashboard with the expected date for things. Do you think you can do this this month or should we wait until April? Again, we don't need to rush this, just keep things in order.

@ericbn
Copy link
Contributor Author

ericbn commented Mar 18, 2025

Oi @leandrodamascena. Just created a PR: #6287

@leandrodamascena leandrodamascena linked a pull request Mar 18, 2025 that will close this issue
7 tasks
@github-project-automation github-project-automation bot moved this from Backlog to Coming soon in Powertools for AWS Lambda (Python) Mar 18, 2025
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) Mar 25, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
event_sources Event Source Data Class utility feature-request feature request
Projects
Status: Shipped
Development

Successfully merging a pull request may close this issue.

2 participants