cargo-aws-lambda

Crates.iocargo-aws-lambda
lib.rscargo-aws-lambda
version0.3.0
sourcesrc
created_at2019-10-25 12:49:30.128393
updated_at2021-10-26 17:32:45.424844
descriptionCross-compile, package and deploy AWS Lambda functions with only docker as a dependency using cargo aws-lambda.
homepagehttps://github.com/vvilhonen/cargo-aws-lambda
repositoryhttps://github.com/vvilhonen/cargo-aws-lambda
max_upload_size
id175590
size61,115
Vesa Vilhonen (vvilhonen)

documentation

https://docs.rs/crate/cargo-aws-lambda

README

cargo aws-lambda

crates.io

Node.js and other dependency free cargo subcommand for cross-compiling, packaging and deploying code quickly to AWS Lambda. Uses softprops/lambda-rust:latest docker image and hence requires docker in PATH, but that's all you need.

Installation

Run cargo install cargo-aws-lambda.

Usage

Go to your project directory and run cargo aws-lambda <ARN> <BIN> to deploy the code to AWS Lambda, where ARN is the full ARN of the Lambda function (e.g. arn:aws:lambda:eu-north-1:123456789123:function:MyLambdaFuncDev) and BIN the name of the binary (e.g. mylambdafunc, if you have src/bin/mylambdafunc.rs with a main function in your project).

    cargo aws-lambda arn:aws:lambda:eu-north-1:123456789123:function:MyLambdaFuncDev mylambdafunc

Optional. If you don't want to pass the function ARN on command-line, you can pass in a key to a function defined in a file named Lambda.toml (example) located in your project's root directory like below.

# Lambda.toml
[arns]
dev = "arn:aws:lambda:eu-north-1:1234:function:MyLambdaFuncDev"
prod = "arn:aws:lambda:eu-north-1:1234:function:MyLambdaFuncProd"

Now you can run the following command to deploy to the first ARN defined.

cargo aws-lambda dev mylambdafunc

You can find full project examples in the examples directory.

The credentials are searched by Rusoto as described in here. If you have AWS CLI configured, most likely everything works without additional configuration. If you want to pass AWS access key and secret as parameters, you can do it at your own risk with the --access-key and --secret-key parameters. In this case, the other processes running in the system can sniff the credentials easily and they're captured in shell history.

All available configuration options can be listed with the --help switch.

Problems?

On windows you must enable the shared drives feature for the drive your project is located in.

How it works?

It mounts your project's directory and your ~/.cargo/registry for the AWS Lambda rust docker image and builds it there for an architecture and system matching the target. After building and stripping symbols out of the executable, everything is packed into a zip file. The zip file is then deployed to the AWS Lambda function ARN given by you. Deploying also instructs AWS to publish the deployed version. Build artifacts generated in docker can be found in your project's target/lambda/release directory.

Commit count: 26

cargo fmt