JSPM

  • ESM via JSPM
  • ES Module Entrypoint
  • Export Map
  • Keywords
  • License
  • Repository URL
  • TypeScript Types
  • README
  • Created
  • Published
  • Downloads 173
  • Score
    100M100P100Q90945F
  • License ISC

A CDK (v2) Construct Library for AWS Lambda in Rust

Package Exports

  • rust.aws-cdk-lambda
  • rust.aws-cdk-lambda/dist/index.js

This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (rust.aws-cdk-lambda) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.

Readme

Amazon Lambda Rust Library


Stability: Experimental npm

This is unofficial CDK library based on the Amazon Lambda Node.js and aws-lambda-rust Libraries.

It's intended for use with the new AWS CDK v2.


This library provides a construct for a Rust Lambda function.

It uses cross for building Rust code, and follows best practices as outlined in the official AWS documentation.

Rust Function

First, import the construct:

import { RustFunction } from 'rust.aws-cdk-lambda';

Now define a RustFunction:

new RustFunction(this, 'my-handler', {});

By default, the construct will use directory where cdk was invoked as directory where Cargo files are located.

If no bin argument is passed in, it will default to the package name as defined in the main Cargo.toml.

Alternatively, directory and bin can be specified:

new RustFunction(this, 'MyLambdaFunction', {
    directory: '/path/to/directory/with/Cargo.toml',
    // Optional
    bin: 'my_lambda',
});

All other properties of lambda.Function are supported, see also the AWS Lambda construct library.

Multiple Rust Lambdas

Assuming you have a CDK project with more than one Rust lambda, there are a couple approaches - as outlined below - that you can use to deploy with cdk.

Multiple Binaries

Suppose your project layout looks like this:

.
├── Cargo.toml
└── src
    └── bin
        ├── lambda1.rs
        └── lambda2.rs

Here's one way to deploy that:

const bin1 = "lambda1";
new RustFunction(this, bin1, {
    bin: bin1,
});

const bin2 = "lambda2";
new RustFunction(this, bin2, {
    bin: bin2,
});

Multiple Packages

Suppose you use Workspaces in your Cargo project instead.

The full contents of the main Cargo.toml would need to be updated to look like this:

[workspace]
members = [
    "lambda1",
    "lambda2"
]

And your new project layout would now look similar to this:

.
├── Cargo.lock
├── Cargo.toml
├── lambda1
│   ├── Cargo.toml
│   └── src
│       ├── main.rs
│       └── utils.rs
└── lambda2
    ├── Cargo.toml
    └── src
        ├── main.rs
        └── utils.rs

Where the utils.rs files are optional, but the point being that they can be imported by the lambda handlers in main.rs if desired.

Now you will only need to update your CDK code to pass package instead, for each workspace member:

const package1 = "lambda1";
new RustFunction(this, package1, {
    package: package1,
});

const package2 = "lambda2";
new RustFunction(this, package2, {
    package: package2,
});