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: Event Source Data Classes for API Gateway WebSocket events #6161

Open
2 tasks done
ericbn opened this issue Feb 25, 2025 · 3 comments
Open
2 tasks done
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.

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: Backlog
Development

No branches or pull requests

2 participants