Realm not working in AWS Lambda (serverless framework)


We have a production app that used to use MongoDB Stitch. Recently we migrated our front-end from using “Stitch” to “Realm-Web” and its working fine. We also have a backend running on AWS Lambda that uses “mongodb-stitch-server-sdk”. We tried migrating to “realm” in the backend but it doesn’t work.

I tried searching online if people are facing a similar challenge and I found this GitHub issue

I am actually facing the exact same issue that is listed there. I wanted to ask here if there are any solutions or workarounds for this.

Also in one of my previous posts, I asked about how long the “Stitch” library might be available as it is legacy library now.

Since we are unable to migrate, I am wondering if we can rely on “Stitch” legacy library to stay alive and possibly how long until all the issues with “realm” is fixed.


The issue is that AWS Lambda doesn’t support all primitive file system operations as Realm JavaScript is using.

If you don’t need to sync data but can you use the functionality supported by Realm Web, you can use Realm Web for node too.

Hi @Kenneth_Geisshirt, I am mainly using “authentication and MongoDB data access” features no syncing features. Can I go ahead then and use “realm-web” for AWS Lambda?

Also do you happen to know if you have to specify “how/where” to store where to store the authentication credentials if you use “realm-web” in AWS Lambda Nodejs environment? I had to do this when using “stitch” library.

const client = Stitch.initializeAppClient(
new StitchAppClientConfiguration.Builder().withDataDirectory("/tmp").build() );

Do we have to do something similar if I used “realm-web” in AWS Lambda? I couldn’t find anything in the docs about it.

Although I havn’t tested this myself, there should be no reason Realm Web couldn’t run on AWS Lambda.

The underlying method of persistence of credentials (refresh + access tokens) is abstracted, but in the time of writing this, only an in-memory storage implementation is available (will be used by default) for Realm Web when running in Node.js. This means a log-in is required in the beginning of every function invocation.

I’m curious to learn more about your need / use-case here. I assume you want to store the refresh + access token of a user to avoid having to re-authenticate on every function invocation, is that correct? How would you ensure that this storage is not shared between different users (executing queries with another users credentials)? (I’m genuinely interested since I havn’t personally built stuff on AWS Lambda myself).

I will relay this to our docs team. I assume this is because Realm JS is our official Node.js SDK, the use of Realm Web from Node.js is supported, but not our recommended way since it doesn’t ship with a sync client.