| Crates.io | bootstrap_aws_lambdas |
| lib.rs | bootstrap_aws_lambdas |
| version | 0.0.5 |
| created_at | 2024-06-21 20:16:27.10707+00 |
| updated_at | 2024-06-23 16:58:06.97334+00 |
| description | Bootstrap AWS Lambda Binaries with Rust |
| homepage | |
| repository | https://github.com/vvivan/bootstrap_rust_aws_lambdas |
| max_upload_size | |
| id | 1279900 |
| size | 8,736 |
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.
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.
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",
});
}
}