bootstrap_aws_lambdas

Crates.iobootstrap_aws_lambdas
lib.rsbootstrap_aws_lambdas
version0.0.5
sourcesrc
created_at2024-06-21 20:16:27.10707
updated_at2024-06-23 16:58:06.97334
descriptionBootstrap AWS Lambda Binaries with Rust
homepage
repositoryhttps://github.com/vvivan/bootstrap_rust_aws_lambdas
max_upload_size
id1279900
size8,736
Ivan Videnovic (vvivan)

documentation

README

Bootstrap AWS Lambda Functions

Crates.io

Use this package to prepare rust binaries so they can be used with CDK lambda constructs. CDK lambda construct expects binary to be named bootstrap.

Usage

Install package as cli tool

cargo install bootstrap_aws_lambdas

and then run:

bootstrap_aws_lambdas <source_path> <target_path>

It is going to discover all exwcutable binaries in source_path and copy eash of them into <target_path>/<binary_name>/bootstrap.

Example

Create rust app and build binaries (for example aws_lambdas_workspace app which is going to build bin_one and bin_two binaries).

Run

bootstrap_aws_lambdas ./target/debug ./build

This package will discover exaecutable binaries bin_one and bin_two and copy them from ./target/debug to ./build/<binary_name>/bootstrap:

aws_lambdas_workspace/target/debug
├── bin_one
├── bin_one.d
├── bin_two
├── bin_two.d
├── build
├── deps
├── examples
└── incremental

to:

aws_lambdas_workspace/build
├── bin_one
│   └── bootstrap
└── bin_two
    └── bootstrap

You are now ready to use any AWS CDK Lambda Construct which can work with binaries. You can check typescript example below:

import * as cdk from "aws-cdk-lib";
import { Construct } from "constructs";
import * as lambda from "aws-cdk-lib/aws-lambda";
import path = require("node:path");

export class CdkTypescriptStack extends cdk.Stack {
  constructor(scope: Construct, id: string, props?: cdk.StackProps) {
    super(scope, id, props);

    // Define the path to the Rust project
    const rustProjectPath = path.join(__dirname, "..", "lambdas");

    const binOneLambda = new lambda.Function(this, "MyFirstRustLambda", {
      runtime: lambda.Runtime.PROVIDED_AL2,
      handler: "bootstrap",
      // this construct expects bootstrap binary at <project_root>/lambdas/bin_one/bootstrap
      code: lambda.Code.fromAsset(path.join(rustProjectPath, "bin_one")),
      functionName: "my-bin-one-lambda",
    });

    const binTwoLambda = new lambda.Function(this, "MySecondRustLambda", {
      runtime: lambda.Runtime.PROVIDED_AL2,
      handler: "bootstrap",
      // this construct expects bootstrap binary at <project_root>/lambdas/bin_two/bootstrap
      code: lambda.Code.fromAsset(path.join(rustProjectPath, "bin_two")),
      functionName: "my-bin-two-lambda",
    });
  }
}
Commit count: 12

cargo fmt