Y-serverless: AWS Lambda + DynamoDB to use as a provider

Hi Everyone!

I built upon this work from this repo to run yjs websockets in a serverless environment. I rewrote in typescript, and made it a tad easier to work with locally (after you deploy the db).

Try it here:

It uses AWS Lambda alongside DynamoDB to maintain socket connections.

A few unique things that I learned:

  1. AWS Lambda supports only supports passing strings as responses. So we need to pass updates to the server and back as base64 strings, and not the standard binary type. This means the y-websocket client doesn’t work out of the box, you need to make a custom copy.

  2. Handling Awareness? I wasn’t entirely clear on how to handle awareness data properly. Right now it just broadcasts the message. In an ideal world, it’s passed to clients as part of the initial document as well.

  3. There was some feedback on the original repo for areas to improve. I tried to apply the updates on just the change vectors, and during updates, but I couldn’t really figure it out.

It does work, but I’m not sure what the right way is to test all of the test cases because it’s not perfect.

To make tweaks, the real work happens in this file in a series of three handlers for the sockets.

1 Like

This is super cool! We have been looking into yjs + serverless ourselves. Getting the websocket provider to work in serverless world would be awesome.

It’s pretty awesome. Because setting up the infra otherwise on EC2 or lightsail is a lot of work.

You should definitely give it a go if you’re looking for something in the space, and maybe if you can fix a few of the weird oddities.

Happy to help get it set up.

@rlingineni I have created a PR on y-websocket that add options to transform data to and from some other type (base64 example in PR description).

That PR looks great. Were you able to get the AWS stuff up and running?

We can probably update the readme to point at the PR.


Just looking at that now, I’m trying to work out the difference between the example server in the y-websockets repo and the one in your repo?

I can see the addition of DynamoDB commands, but I wasn’t sure about the removal of the awareness code.

Is an Express server required? Or is that just for dev purposes? Apologies, misread the Readme