-
Notifications
You must be signed in to change notification settings - Fork 89
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 Bundles #7
Comments
The new If This means that, for example, bundling tools such as In a sense, this is somewhat aligned with how docker assets work. We only include the source of the image in the cloud assembly, and only during publishing, we actually build the docker image. I am wondering if perhaps the right approach is to move Lambda bundling into the publishing stage. This means that during synthesis, we will only copy the sources to the cloud assembly and we will add some hooks to the publishing stage ( There is an interesting synergy related to Docker. We eventually want to bundle lambda functions inside a docker container that matches the Lambda environment, and the publishing environment supports docker. Maybe the right, general purpose, solution is to basically treat these more like a docker asset than a .zip asset. |
As a developer who uses CDK, i'd rather get Lambda creation errors as soon as possible (aka cdk synth) and not wait until the cdk deploy part where it deploys other items. To me, a solution would be that during the python lambda creation a docker container (with python dep and pipenv/poetry) will run, and pull the requirements into an output folder which can be then zipped. Each language, nodejs/python etc, will just spin up a different builder docker image but the logic can be the same overall. |
Yes, I retract my proposal to do this during publishing. It won't work because you need dependencies from your project and those won't be available in the cloud assembly. So this needs to happen either during build, before synth (and then during synth we will basically have a bundle that we can just reference as a .zip file) or it can happen during synth, but we need some way to abstract away any dependencies. Let's examine these two options. Before synthIn this option, the preparation of the bundle happens sometimes before we call This is technically already supported, but requires that users will codify this in their library build process (see the prebuild configuration in s3-deployment's package.json and the actual lambda build script). It's not too hard, but also not a great developer experience. It is important to notice that when building libraries the CDK CLI is not involved at all. The CLI is only used by applications not when building and publishing libraries. This is just a normal TypeScript library. Therefore, in this approach, we basically need to vend another command line tool that users will be able to integrate into their build system which will prepare these bundles and allow them to be referenced by the CDK library. It won't be possible to rely configuration from the app to this new tool because the app is never executed when you build a library, so we will need some additional configuration that will be read by the CDK to identify the bundled assets. A downside of this approach is also that the eventual library can technically be pretty big because it will include the compiled zip file with all it's dependencies, so we are not leveraging the standard dependency mechanisms. During synthIn this approach we are basically saying that bundling only happens when the app is actually synthesized. This is similar to how One way to do that would be to always require that bundling happens inside a Docker container. This has the benefit of reducing the dependency surface area (consumers only need docker during synth) and will also allow us to actually build Lambda functions in a lambda-compatible container (like The main benefits of this approach:
Downsides:
|
I think that the CDK should offer the best possible developer experience so I would definitely go for the during synth option. Building inside a Docker container is indeed the right solution for maximum compatibility. But the main question is what kind of build workflow will run inside the container. The worklows here https://github.com/awslabs/aws-lambda-builders/tree/develop/aws_lambda_builders/workflows (= As far as JavaScript/TypeScript is concerned I'm not sure that the worklow offered by
We should maybe start with a minimum set of requirements: what is important/critical? what use cases do we want to support? |
I tend to agree that synth is more inline with how we want CDK experience to work. Ideally we should offer some kind of an open framework for building assets inside docker images during synthesis. The minimal surface can be something like "run this command inside a docker image with two mounted volumes: Then, we can implement our parcel bundler using something like this, and also perhaps implement an additional builder that leverages |
Hey @eladb, I'm sure you've seen aws/aws-cdk#6535... I've been working further on this to come up with the best possible developer experience for JS/TS Lambda functions. I have now a working construct offering the following API: Code can be defined inside the construct and it can use any top level dependency imported in the file (another file or an external module). This offers a really great developer experience. I'm using the Typescript Compiler API to analyze the AST for this. It We can discuss this further when you're available. |
@eladb can we start the discussion with this? It works like this:
Moreover we have the following features:
|
Description
bucket.grantXxx(lambda)
will also addBUCKET_ARN
environment variable)Progress
The text was updated successfully, but these errors were encountered: