There are a number of projects available now where people are experimenting with serverless WebAssembly in one form or another. For example, Geoffrey Couprie has written serverless-wasm,[54] a framework that starts up an HTTP server and, through a toml configuration file, can route HTTP requests to different wasm modules. The host contract for this framework looks like this (at the time this book was finished):
| mod sys { |
| extern { |
| pub fn log(ptr: *const u8, size: u64); |
| pub fn response_set_status_line(status: u32, ptr: *const u8, size: u64); |
| pub fn response_set_header(name_ptr: *const u8, name_size: u64, |
| value_ptr: *const u8, value_size: u64); |
| pub fn response_set_body(ptr: *const u8, size: u64); |
| pub fn tcp_connect(ptr: *const u8, size: u64) -> i32; |
| pub fn tcp_read(fd: i32, ptr: *mut u8, size: u64) -> i64; |
| pub fn tcp_write(fd: i32, ptr: *const u8, size: u64) -> i64; |
| pub fn db_get(key_ptr: *const u8, key_size: u64, |
| value_ptr: *const u8, value_size: u64) -> i64; |
| } |
| } |
This framework allows WebAssembly modules to read and write over raw TCP connections as well as make connections to a database back-end. As I mentioned earlier, this contract can be satisfied by anything, including a mock host which makes testing these modules fairly easy. It’s up to you whether you decide to let your modules make external connections.
Colin Eberhardt takes a different approach in his blog post,[55] where the WebAssembly function written in Rust is hosted in AWS’s NodeJS Lambda runtime. This is certainly a far simpler way to host a WebAssembly module than trying to manipulate all of the lower-level Rust APIs you’ve seen in this book to host a module. Using NodeJS as the host runtime means the Rust WebAssembly module developer can take advantage of wasm-bindgen, making it even easier to write modules.
Yet another option available for serverless WebAssembly is the use of Cloudflare Workers. They just recently announced support for WebAssembly workers[56] and you can use the wasm-pack tool to bundle up your WebAssembly code and deploy it to Cloudflare, as illustrated in their blog post[57] covering the subject. This support is still JavaScript-based, so it resembles using a NodeJS runtime in AWS to invoke a WebAssembly module, but this is definitely an indication that the future of serverless WebAssembly is a bright one.
3.142.12.170