-
Notifications
You must be signed in to change notification settings - Fork 4k
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
Lambda "build" assets #1435
Comments
Copy @jfuss |
Additional context:
|
Working with aws-lambda-builders to extract the logic within SAM that maps a function runtime to a build workflow, e.g. taking a java8 function and determining if it's a maven or gradle project by looking for a const myFunction = new lambda.JavaFunction(stack, 'MyJavaFunction', {
projectPath: './lambda'
}); |
I am currently using the asset's const gradle = new lambda.Function(stack, 'Gradle', {
code: lambda.Code.build('./gradle-project'),
runtime: lambda.Runtime.Java8,
handler: 'com.example.Main:handle'
}); It's simple, but I like the idea of a type-safe const myFunction = new lambda.JvmFunction(stack, 'MyJavaFunction', {
projectPath: './lambda',
dependencyManager: 'maven'
}); Which begs the question: what information should be injectable as props and what information should be inferred by the tool? |
Yes, for example, Layers also use the same Code mechanism. Maybe we should define an interface :-)
I think the default behavior should be to infer as much as possible, but I really like the option of letting users specify many of the project settings here (like dependencies etc) if they wish. |
Layers changes things up a bit because they aren't specific to a single runtime: I see the following options for proceeding:
const fn = new lambda.Function(this, 'F', {
runtime: lambda.Runtime.Java8,
code: lambda.Code.build({
path: './path',
language: lambda.Runtime.Java8,
// maybe we only need to pass the family, not the specific language and infer the rest?
// language: lambda.RuntimeFamily.Java,
})
});
const fn = new lambda.Layer(this, 'F', {
code: lambda.Code.build({
path: './path',
language: lambda.Runtime.Java8
})
});
const fn = new lambda.PythonFunction(this, 'F', {
path: './path',
version: '3.7'
});
const layer = new lambda.NodeLayer(this, 'L', {
path: './path',
});
const fn = new lambda.Function(this, 'F', {
runtime: lambda.Runtime.Java8,
code: new JvmCode('./path')
});
const layer = new lambda.Layer(this, 'L', {
code: new NodeCode('./path'),
compatibleRuntimes: [
lambda.Runtime.NodeJs,
lambda.Runtime.NodeJs810,
// etc.
]
});
// the static method could still be useful for discoverability and consistency.
// again, requires redundant 'runtime' information to be passed
const fn = new lambda.Function(this, 'F', {
runtime: lambda.Runtime.Java8,
code: lambda.Code.java('./path')
}); I'm leaning towards a layered approach incorporating option 2. and 3. - provide high-level |
Hey guys, is there any progress on the issue for typescript version? |
Hi there, is there any news on this feature? Thank you |
Unfortunately, we don't yet have a plan or update on this feature at this time. @andreimcristof - this issue is only focusing on using the lambda builders tooling, i.e., equivalent of If you're only looking to invoke |
I think at a minimum we should provide guidance on how to use the SAM build capabilities as a pre synthesis step in order to produce lambda bundle zip files that can later be referenced as file assets for Lambda code. |
@nija-at but can sam build and the cdk not play nice with eachother? Meaning: before initializing the cdk infra, I trigger a sam build, and customise the path of the cdk lambdas to read from the sam build output? Can that not work? because, if I understood correctly, all that the cdk needs for the functions, is a path where to read the zips from:
... so then, I just configure the .fromAsset to read from the sam build output?
|
I had the same problem and solved it by having a separate stack for storing the lambda archives on S3, and before the stack is deployed building and uploading the lambdas so they can be referenced in CDK from the bucket: https://coderbyheart.com/how-i-package-typescript-lambdas-for-aws/ |
@eladb are there plans to make a |
No concrete plans but more than happy to take contributions! Bundling is the right way. |
Thanks for the reply! I might just do that, though it'll be a while before I have time :) |
We would like to leverage the aws-lambda-builders project (part of SAM CLI) in order to allow CDK users to build AWS Lambda bundles.
Requirement (API sketch):
Ideally, this is all the user should need to specify. The
lambda.Code.build
class should be able to deduce most of the information needed in order to tell the toolkit to invoke aws-lambda-builders via it's JSON RPC protocol when assets are prepared (similar to any other asset).Notes:
pip install
. We should consider if the toolkit can do this automatically upon first use?The text was updated successfully, but these errors were encountered: