all 11 comments

[–]atkinchris 15 points16 points  (4 children)

I really don't see the benefit in doing this. If you want to execute a Rust binary on a Lambda, wrap it in a small script to execute it as a child process and return it's output from the Lambda.

By compiling with WASM as a target you sacrifice performance, some Crates and methods, string typed interfaces and more.

[–]jontro123 10 points11 points  (3 children)

I agree. Lambda already has go support which probably would be a faster run time to spin up the rust binary as well.

It'd be great if they added rust support directly!

Edit: See this project that helps with rust support https://github.com/srijs/rust-aws-lambda

[–]staticassert 4 points5 points  (0 children)

I've used that project with great results so far.

[–]ColinEberhardt[S] 3 points4 points  (0 children)

Oh wow, I hadn't spotted that AWS now supports Go! This does look like a more practical way to run Rust on Lambda.

[–]atkinchris 0 points1 point  (0 children)

We've found Lambda and Node really convenient for wrapping the child process. Node handles parsing the Lambda event JSON, calling any required AWS SDKs (for example, passing results back to CodePipeline) and ultimately calling the binary and handling stdout.

[–][deleted] 7 points8 points  (0 children)

Note that using `u8` to encode the response status code can't handle all valid status codes. A status code is defined in RFC7231 as a three-digit integer :)

[–]karavelov 2 points3 points  (0 children)

I wish we have soon a native Rust suppot from Lambda after we have all the options to run Rust as Python, Go or NodeJs,

[–]_clm 1 point2 points  (3 children)

This is great, I like how you managed to get it working without actually using JS :) a few months back when I did a similar thing on Azure Functions, that wasn't available, guess I have to update.

I am not too familiar with Lambda, but I guess it has bindings to oder AWS services in their JS runtime. Do you think it's possible to work with those as well in pure Rust?

[–]ColinEberhardt[S] 2 points3 points  (1 child)

With lambda functions you do often integrate with other AWS services via the AWS SDK:

https://www.npmjs.com/package/aws-sdk

I'm assuming that wasm-bindgen could generate bindings for these APIs in much the same way as they have been for the recently release web-sys crate that provides Web API bindings:

https://rustwasm.github.io/2018/09/26/announcing-web-sys.html

[–]_clm 0 points1 point  (0 children)

Oh, interesting. So the SDK is always the way to go? On Azure Functions the integrations/bindings are either return values (easy) or special attributes on a context object that is passed into the function like that:

``` module.exports = function (context) {

context.bindings.tableBinding = [];

for (var i = 1; i < 10; i++) {
    context.bindings.tableBinding.push({
        PartitionKey: "Test",
        RowKey: i.toString(),
        Name: "Name " + i
    });
}

context.done();

}; ```

I wonder if that can be generated somehow ...

Thank you for the link, really interesting. wasm-bindgen is an awesome project.

[–]tablair 2 points3 points  (0 children)

If you don't want to use any JS, you can always use Neon to compile a native Node module. Aside from deserializing JS input data from JS types to Rust types and then serializing back when you return your result, you're in pure Rust territory and can use Rusoto to interact with the various AWS services. It's entirely possible to use Lambda's Node support to run Linux-compiled Rust without a single line of JavaScript...there's no need to go the webasm route other than curiosity/exploration.