-
Notifications
You must be signed in to change notification settings - Fork 140
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Bug: Cannot build projects with multiple Rust-based Lambdas and using Cargo workspaces #634
Comments
Current workaround:Build the lambdas manually and force them to be built in their own folders: # build function_a
cd function_a
CARGO_TARGET_DIR=target cargo lambda build --release
cd ..
# build function_b
cd function_b
CARGO_TARGET_DIR=target cargo lambda build --release
# build with SAM (it will rebuild and place your lambdas in `./target/lambda` but then it will copy the files into the final build folder from the previous manual builds
sam build --beta-features --debug |
Even simpler workaroundI just realised that this works as well: CARGO_TARGET_DIR=target sam build --beta-features |
Hi @lmammino Thanks for raising the issue and providing the workarounds. I'll move the issue to Lambda Builders since the fix will be there. |
Here's a brief description of what the fix will look like - in https://github.com/aws/aws-lambda-builders/blob/develop/aws_lambda_builders/workflows/rust_cargo/cargo_lambda.py#L72, add the env var |
Patch is released in v1.50.0. If you are AWS SAM CLI user, please wait for next AWS SAM CLI release. Closing |
Description:
When creating multiple lambda functions in Rust, it is a common practice to organise functions in independent cargo subprojects and then use a cargo workspace at the top level.
This is convenient because it allows to have shared crates that can be imported by multiple lambdas in the project.
Something that might look like this in terms of files structure:
When trying to build this project with
sam build --beta-features
it produces the following error:My understanding of the problem is the following:
When using workspaces all the targets are produced in the root folder of the project: so in the example above:
./target/lambda/function_a
./target/lambda/function_b
But the SAM integration with
cargo-lambda
is not aware of this and keeps looking for the binaries in:./function_a/target/lambda/function_a
./function_b/target/lambda/function_b
And therefore the error mentioned above is raised.
Also, note that the current documentation doesn't seem to cover this particular case, so if this is fixed, it's probably worth adding a new example there.
Finally, as far as I know,
cargo-lambda-cdk
correctly support this particular use case.Steps to reproduce:
I have created a sample repo here: https://github.com/lmammino/broken-sam-cargo-lambda-workspaces-example
git clone git@github.com:lmammino/broken-sam-cargo-lambda-workspaces-example.git
cd broken-sam-cargo-lambda-workspaces-example.git
sam build --beta-features --debug
Additional environment details (Ex: Windows, Mac, Amazon Linux etc)
sam --version
: SAM CLI, version 1.113.0The text was updated successfully, but these errors were encountered: