Comments (2)
Hi @timkaas, first off thanks for opening this issue. I had a look, and realized that you are totally right - this is likely because we only call cargo lambda
once by default on all bins/workspaces in a project, so the first buildEnvironment
that the RustFunction
encounters is the one that will be used for a first-time (and project wide) compilation.
More info and context can be found in these lines:
https://github.com/rnag/rust.aws-cdk-lambda/blob/main/lib/build.ts#L116-L138
As can be seen, shouldCompile
is a boolean flag and is only true for once per project, or else is always true when BUILD_INDIVIDUALLY
is enabled.
Additionally, it can also be seen, that we default to BUILD_ENVIRONMENT
if buildEnvironment is not passed in to RustFunction
the first time:
options.buildEnvironment ||
Settings.BUILD_ENVIRONMENT;
Per these notes above, I would say that it might be slightly more performant to only call cargo lambda
once per project, rather than once per RustFunction
(which can easily add up if you have a lot of them).
I would suggest using Settings.BUILD_ENVIRONMENT
in this case, and having merged environment defined under there:
Settings.BUILD_ENVIRONMENT = {
FOO_ENV: 'foo',
BAR_ENV: 'bar',
};
// this appends 'lambda' folder to the directory where `cdk` was invoked
// note that this should be the same as passing `directory` to each RustFunction as above
Settings.WORKSPACE_DIR = 'lambda'
const foo_lambda = new RustFunction(this, 'foo_lambda', {
package: 'foo',
// don't use `buildEnvironment` as we want to default to merged environment above
})
const bar_lambda = new RustFunction(this, 'bar_lambda', {
package: 'bar',
// don't use `buildEnvironment` as it will be ignored here
})
Please do try that out, and let me know how it goes.
from rust.aws-cdk-lambda.
A few TODO items I see, and potential areas of improvement in terms of documentation and clarity purposes:
- Documentation should be updated to indicate that
BUILD_INDIVIDUALLY
should be enabled (true
) when multiple instances ofbuildEnvironment
are passed in, since only the first value ofbuildEnvironment
will be used for compilation step (sincecargo lambda
only runs once per project). - We should definitely log or print out a user-friendly warning when subsequent
buildEnvironment
is encountered, butshouldCompile
is false, meaning compilation step was already run. I feel a friendly message would be to suggest merging those env values intoSettings.BUILD_ENVIRONMENT
instead, before declaring anyRustFunction
s; or else enablingBUILD_INDIVIDUALLY
as that could be another option. - If
buildEnvironment
is passed in to aRustFunction
butSettings.BUILD_ENVIRONMENT
is also defined at this point, we should similarly display a warning, because these two should be mutually exclusive (one or the other, but not both).
from rust.aws-cdk-lambda.
Related Issues (10)
- Don't build on synth HOT 5
- openssl when cross compiling HOT 3
- How can I test locally using `sam local start-lambda` with this setup? HOT 1
- Unhelpful error thrown when cargo is missing HOT 2
- Local dependencies HOT 1
- Use cargo-lambda for compilation HOT 1
- Hardcode or specify a glibc version for compilation
- Add an option to compile code in a Docker container HOT 2
- cdk destroy shouldn't rebuild the lambda? HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from rust.aws-cdk-lambda.