Is any aws service suitable for sending real time updates to browser?
Asked Answered
N

2

15

I'm developing a stocks app and have to keep users browser updated with pricing changes

I don't need to access past data, browser just have to get current data whenever it changes

is it possible to filter a dynamodb stream and expose an endpoint (behind api gateway) that could be used with a javascript EventSource?

Nard answered 27/1, 2018 at 10:47 Comment(0)
S
14

I realize this is not using Server Sent Events but AWS just announced Serverless WebSockets for API Gateway. Pricing is based on minutes connected and number of messages sent.

Product Launch Article: https://aws.amazon.com/about-aws/whats-new/2018/12/amazon-api-gateway-launches-support-for-websocket-apis/

Documentation: https://docs.aws.amazon.com/apigateway/latest/developerguide/apigateway-websocket-api.html

Pricing: https://aws.amazon.com/api-gateway/pricing/

Superincumbent answered 20/12, 2018 at 16:56 Comment(0)
L
8

API Gateway is a store-and-forward service. It collects the response from whatever the back-end may happen to be (Lambda, an HTTP server, etc.) and then returns it en block to the browser -- it doesn't stream the response, so it would not be suited for use as an Eventsource.

AWS doesn't currently have a managed service offering that is obviously suited to this use case... you'd need a server (or more than one) on EC2, consuming the data stream and relaying it back to the connected browsers.

Assuming that running EC2 servers is an acceptable option, you then need HTTPS and load balancing. Application Load Balancer supports web sockets, so it also might also support an eventsource. A Classic ELB in TCP (not HTTP) mode should support an eventsource without a problem, though it might not correctly signal to the back-end when the browser connection is lost. Both of those balancers can also offload HTTPS for you. Network Load Balancer would definitely work for balancing an eventsource, but your instances would need to provide the HTTPS, since NLB doesn't offload it for you.

A somewhat unorthodox alternative might actually be AWS IoT, which has built-in websocket support... Not the same as eventsource, of course, but a streaming connection nonetheless... in such an environment, I suppose each browser user could be an addressable "thing."

Leukoderma answered 28/1, 2018 at 1:51 Comment(2)
AWS have managed service "WebSocket APIs" supported today on API GatewayWorkingman
@OlegYudovich yes, the available services have changed since this was written. I will update.Leukoderma

© 2022 - 2024 — McMap. All rights reserved.