[lambda-nodejs] Deploy additional files alongside bundled output
See original GitHub issueI want to be able to push up some additional files along with the bundled output. One way of doing this would be to expose a hook that allows augmenting the bundling commands.
Use Case
I’m trying to deploy a lambda function that uses the Prisma database client. They have a guide using the serverless cli to deploy to lambda but I was hoping to use cdk since I have other infrastructure to manage as well.
The prisma database client is generated based on a schema.prisma
file that itself is generated by introspecting the database. It actually automatically performs this generation on install, so my hope was that I could
- Specify
nodeModules: ["@prisma/client", "@prisma/cli"]
- Bundle up the rest of the function and dependencies
- When install occurs, the client get generated as normal
The problem is that the schema.prisma
file isn’t copied to the output directory and I don’t think there’s a way for me to accomplish that. Ideally I would like to make use of the bundling functionality while still having some control over what else gets deployed.
Proposed Solution
Perhaps expose a hook to inject custom commands? This is the area of interest. I got something working hacking around node_modules where all I need to do is insert a cp schema.prisma ${options.outputDir}
in between parcelCommand
and depsCommand
. So I was thinking a function like this:
const fn = new lambda.NodejsFunction(this, "MyCDKFunction", {
nodeModules: ["@prisma/client", "@prisma/cli"],
handler: "handler",
entry: "lib/index.ts",
modifyBundleCommand: ({ parcelCommand, depsCommand, options }) => {
return [parcelCommand, `cp schema.prisma ${options.outputDir}`, depsCommand];
}
});
The default would just be ({ parcelCommand, depsCommand }) => [parcelCommand, depsCommand]
to maintain the default behavior.
- 👋 I may be able to implement this feature request
- ⚠️ This feature might incur a breaking change
This is a 🚀 Feature Request
Issue Analytics
- State:
- Created 3 years ago
- Reactions:5
- Comments:8 (5 by maintainers)
Top GitHub Comments
We could have something like this:
Add a
additionalCommands
prop of typeICommand
:Not when doing local bundling https://github.com/aws/aws-cdk/tree/master/packages/%40aws-cdk/aws-lambda-nodejs#local-bundling