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

AWS Lambda Cannot find module /var/task/node_modules/realm/compiled/napi-v4_linux_x64/realm.node #3583

Closed
cloudworkpro-sean opened this issue Feb 11, 2021 · 3 comments

Comments

@cloudworkpro-sean
Copy link

cloudworkpro-sean commented Feb 11, 2021

I am trying to run a simple auth function on AWS Lambda using Realm-js with Server API Key authentication. When hitting the endpoint I get a node error.

Goals

I am trying to authenticate a server user using Realm

Expected Results

return the user object

Actual Results

	ERROR	Uncaught Exception 	{
"errorType":"Runtime.ImportModuleError",
"errorMessage":"Error: Cannot find module '/var/task/node_modules/realm/compiled/napi-v4_linux_x64/realm.node'
Require stack:
- /var/task/node_modules/realm/lib/index.js
- /var/task/dist/login.js
- /var/runtime/UserFunction.js
- /var/runtime/index.js","stack":["Runtime.ImportModuleError: Error: Cannot find module
'/var/task/node_modules/realm/compiled/napi-v4_linux_x64/realm.node'",
"Require stack:","- /var/task/node_modules/realm/lib/index.js","- /var/task/dist/login.js",
"- /var/runtime/UserFunction.js","- /var/runtime/index.js",
"    at _loadUserApp (/var/runtime/UserFunction.js:100:13)",
"    at Object.module.exports.load (/var/runtime/UserFunction.js:140:17)","    at Object.<anonymous> (/var/runtime/index.js:43:30)",
"    at Module._compile (internal/modules/cjs/loader.js:1063:30)",
"    at Object.Module._extensions..js (internal/modules/cjs/loader.js:1092:10)",
"    at Module.load (internal/modules/cjs/loader.js:928:32)",
"    at Function.Module._load (internal/modules/cjs/loader.js:769:14)",
"    at Function.executeUserEntryPoint [as runMain] (internal/modules/run_main.js:72:12)",
"    at internal/main/run_main_module.js:17:47"]}

Steps to Reproduce

Deploy the following function to Lambda and make a post request to it.

Code Sample

import Realm from "realm";
const serverless = require('serverless-http')
const express = require('express')
const bodyParser = require('body-parser')
import { getSecret } from '@techlinksolutions/get-aws-secrets'

const app = express()
app.use(bodyParser.json())
const region = process.env.REGION

  async function login() {
    const secretRes = await getSecret('APP_ID_KEY_NAME', region)
 
    const id = secretRes.SecretString
    console.log(id);
    const config = {
        id,
    }
    const app = new Realm.App(config)
    
    const credentials = Realm.Credentials.serverApiKey(
          API_KEY_HERE
      );

    const user = await app.logIn(credentials);
    return user;
}

app.post('/auth/login', async function(req, res) {
    res.set({
        'Access-Control-Allow-Origin': '*',
        'Access-Control-Allow-Credentials': true,
    })
    
    res.send(await login())
})

module.exports.handler = serverless(app)

Version of Realm and Tooling

  • Realm JS SDK Version: 10.2.0
  • Node or React Native: Node
  • Client OS & Version: MacOS Catalina 10.15.7
  • Which debugger for React Native: N/A
@kneth
Copy link
Contributor

kneth commented Feb 12, 2021

The error message indicates that the Realm module isn't installed. As I recalled it, AWS has a bug which prevent Realm to work correctly - see #2509.

@cloudworkpro-sean
Copy link
Author

Thanks @kneth! This should be included in the docs until it's fixed. I tried the work around in #2509 but its not working for me. Still getting the same error. I think we'll hold off using Realm for now. Thanks for the help!

@kneth
Copy link
Contributor

kneth commented Feb 15, 2021

@cloudworkpro-sean #3591

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Mar 15, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

2 participants