2

I am writing some code in the rust and compiling it to wasm to run it using node.js runtime for lambda@edge. I need to generate the uuid as part of this code. I am doing that in rust and the code is compiling. But when I run, it is throwing below exception (And it is in my local environment before deploying to lambda, so no AWS environment issue)

panicked at 'could not retrieve random bytes for uuid: Node.js crypto module is unavailable', /Users/user/.cargo/registry/src/github.com-1ecc6299db9ec823/uuid-0.8.2/src/v4.rs:31:13

Stack:

Error
    at _.exports.__wbg_new_693216e109162396 (/Users/user/tech/DataPlatform/RustLambda/build.function/origin-request.js:1:3651)
    at wasm-function[124]:0x10671
    at wasm-function[705]:0x21211
    at wasm-function[223]:0x17ad0
    at wasm-function[327]:0x1bc2e
    at wasm-function[521]:0x1ff7d
    at wasm-function[544]:0x20402
    at wasm-function[445]:0x1e9c4
    at wasm-function[303]:0x1ae09
    at wasm-function[310]:0x1b1fd


(node:36099) UnhandledPromiseRejectionWarning: RuntimeError: unreachable
    at wasm-function[223]:0x17b06
    at wasm-function[327]:0x1bc2e
    at wasm-function[521]:0x1ff7d
    at wasm-function[544]:0x20402
    at wasm-function[445]:0x1e9c4
    at wasm-function[303]:0x1ae09
    at wasm-function[310]:0x1b1fd
    at wasm-function[67]:0x59f1
    at wasm-function[320]:0x1b80b
    at wasm-function[127]:0x10b8f
(Use `node --trace-warnings ...` to show where the warning was created)
(node:36099) UnhandledPromiseRejectionWarning: Unhandled promise rejection. This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not handled with .catch(). To terminate the node process on unhandled promise rejection, use the CLI flag `--unhandled-rejections=strict` (see https://nodejs.org/api/cli.html#cli_unhandled_rejections_mode). (rejection id: 1)
(node:36099) [DEP0018] DeprecationWarning: Unhandled promise rejections are deprecated. In the future, promise rejections that are not handled will terminate the Node.js process with a non-zero exit code.

Here is my code snippet in the rust

        let visitor_id = Uuid::new_v4();
        debug_log!("visitor_id: {:#?}", visitor_id);
    }

I am using uuid crate as

use uuid::Uuid;

and the dependencies are here

uuid = { version = "0.8", features = ["v4", "wasm-bindgen"] }
getrandom = { version = "0.2", features = ["js"] }

Any idea how to proceed with creating the UUID here?

Vikas
  • 21
  • 3
  • 1
    What do you get when you run `node -e "console.log(require('crypto').randomBytes)"`? It seems to be an issue loading the Node.js `crypto` module. – smitop Dec 18 '21 at 02:18
  • This is the output I got ```node -e "console.log(require('crypto').randomBytes)" [Function: randomBytes] ``` – Vikas Dec 19 '21 at 17:26

0 Answers0