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

Is the SNS necessary in your design? #89

Closed
tomaszdudek7 opened this issue Nov 25, 2023 · 3 comments
Closed

Is the SNS necessary in your design? #89

tomaszdudek7 opened this issue Nov 25, 2023 · 3 comments
Labels
enhancement New feature or request

Comments

@tomaszdudek7
Copy link

Hi there. I'm just wondering if the SNS as the "decoupling" mechanism is necessary and/or if there was a specific requirement or reasoning behind it.

Your flow of getting a response from a model is as follows:

  1. front-end connects to a websocket - which, under the hood, invokes the publisher Lambda - but it doesn't do much due to route_key being equal to $connect
  2. then, front-end sends the user prompt to the open websocket (
    ws.send(JSON.stringify({ ...input, token }));
    ) - it also triggers the same publisher Lambda. However, this time, it actually pushes the prompt forward to the SNS because the route_key is different.
  3. now, the SNS invokes the websocket Lambda, which streams the response back to the websocket (https://github.com/aws-samples/bedrock-claude-chat/blob/main/backend/app/websocket.py#L77)

However, if (instead of being SNS consumer) your websocket Lambda was just a different route on the WS API gateway (lets call it /invoke), then the flow could look as follows:

  1. front-end connects to a websocket - which, under the hood, invokes the publisher Lambda - but it doesn't do much due to route_key being equal to $connect
  2. front-end sends the user prompt to the open websocket as an action /invoke - it triggers the websocket Lambda

Voila, you no longer need the SNS and it still works the same way.

Am I missing something (could be totally wrong above of course)? Is the SNS here necessary? Does it provide any additional value over this alternative method that I've described which would simplify the design?

Other than that - great work. Thanks for providing this excellent blueprint!

@ctodd
Copy link

ctodd commented Dec 5, 2023

Tomaz, check out the Readme under Architecture. I just happened to read this myself and was wondering the same thing. :-)

[Amazon SNS]: Used to decouple streaming calls between API Gateway and Bedrock because streaming responses can take over 30 seconds in total, exceeding the limitations of HTTP integration (See quota).

@statefb
Copy link
Contributor

statefb commented Dec 5, 2023

@tomaszdudek7
Thank you for your suggestion. We re-verified the behavior of http integration and confirmed that lambda can continue to send message to websocket connection after 30 sec passed although the message Endpoint request timed out sent. So I believe that we can simplify the architecture with front-end implementation which ignore the message saying timed out. We'll modify when we have time (PR is also welcome), thank you!

@statefb statefb added the enhancement New feature or request label Dec 5, 2023
@tomaszdudek7
Copy link
Author

@ctodd Yes, but my point was that SNS is not even required here, as confirmed in the comment above.

@statefb statefb closed this as completed in 69098df Mar 7, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

3 participants