Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/svozza/node-rust-wasm-lambda
A sample project for compiling a Rust module to WASM and using JCO to import it in Node.js AWS Lambda function
https://github.com/svozza/node-rust-wasm-lambda
Last synced: about 1 month ago
JSON representation
A sample project for compiling a Rust module to WASM and using JCO to import it in Node.js AWS Lambda function
- Host: GitHub
- URL: https://github.com/svozza/node-rust-wasm-lambda
- Owner: svozza
- Created: 2024-05-28T10:36:01.000Z (6 months ago)
- Default Branch: main
- Last Pushed: 2024-05-30T17:38:22.000Z (6 months ago)
- Last Synced: 2024-06-26T01:21:22.368Z (5 months ago)
- Language: Rust
- Homepage:
- Size: 24 MB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# Node.js and WASM Lambda
## Introduction
This is a sample project for compiling a Rust module to WASM and using JCO to import it in a Node.js
AWS Lambda function.## Prerequisites
You must have the following tooling installed
- [Rust](https://www.rust-lang.org/tools/install)
- [Node.js](https://nodejs.org/en/download/package-manager/current)
- [cargo-component](https://github.com/bytecodealliance/cargo-component)## Setup
Note: This is based on the JCO launch announcement [blog post](https://bytecodealliance.org/articles/jco-1.0) but
the steps appear to be outdated so what follows is the changes required to make it work as of 2024-05-25.The project was created by running the following `cargo-component` command:
```shell
cargo component new --lib
```
This creates a component in `src/lib.rs` that has a simple Hello World function. This function was changed to one
that will turn a string into upper case:```rust
impl Guest for Component {
fn shout(input: String) -> String {
let mut s = input.to_uppercase();
s.push_str("!");
s.into()
}
}
```The `wit/world.wit` file which uses the [IDL(https://github.com/WebAssembly/component-model/blob/main/design/mvp/WIT.md)]
that underpins the WebAssembly component model was also changed:```
package component:;world example {
export shout: func(input: string) -> string;
}
```## Instructions:
1. Run `npm i` to install the `@bytecodealliance/jco` and`@bytecodealliance/preview2-shim` dependencies
aqqqlocally.
2. Run `npm run build` to compile the Rust module, invoke JCO and then build a zip file of the code
in a folder called `dist`.
3. Create a blank Node.js AWS lambda function.
4. Upload the zip to the lambda function.
5. Execute the lambda function with the default test event, which should produce the following output:```
"VALUE1!"
```