简体   繁体   English

使用节点 Lambda Function AWS CDK 部署其他文件

[英]Deploy additional files with Node Lambda Function AWS CDK

I'm trying to deploy my AWS lambda function using the CDK, but I want to bundle other files in the lambda as well (JSON files).我正在尝试使用 CDK 部署我的 AWS lambda function,但我想在 lambda 中捆绑其他文件(JSON 文件)。 How do I go about this other than using CommandHooks and copying the files myself?除了使用 CommandHooks 和自己复制文件之外,我该如何解决这个问题? For reference, I'm not importing the file.作为参考,我没有导入文件。 A library I'm using is importing it and requires the path to the file as a string.我正在使用的库正在导入它,并且需要文件的路径作为字符串。 I've tried using the loader option, but that changes the name of the file and breaks the path that the library was given.我尝试过使用 loader 选项,但这会更改文件的名称并破坏给定库的路径。

For reference, this works: https://github.com/aws/aws-cdk/issues/11468作为参考,这个作品: https://github.com/aws/aws-cdk/issues/11468

but I'd prefer having to do that for every lambda.但我宁愿对每个 lambda 都这样做。

If the functions all share the same files, then you might prefer to create a Lambda layer to copy the files over.如果这些函数都共享相同的文件,那么您可能更愿意创建一个Lambda 层来复制文件。

If each function requires different files however, then the bundling option is just as easy.但是,如果每个 function 需要不同的文件,那么捆绑选项同样简单。 It's IAC after all, so you can just create a helper function to make it a bit less repetitive.毕竟是 IAC,所以您可以创建一个帮助程序 function 以减少重复性。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM