如何使用AWS CDK在cdk构建上安装lambda函数的依赖项

问题描述:

在使用AWS SAM时,我曾经运行过build命令,该命令将遍历我所有的Lambda函数包并安装它们的依赖项(在它们上运行npm install).

When using AWS SAM I used to run build command which would go through all of my Lambda function packages and install their dependencies (run npm install on them).

如何使用AWS CDK实现相同的行为?它似乎不是自动执行的,还是我缺少了什么?

How can I achieve the same behavior with AWS CDK? It doesn't seem to do it automatically, or am I missing something?

此功能确实缺失.您需要编写自己的包装.请记住,如果任何依赖项(例如Numpy)使用带有本机C代码的共享库,则lambda依赖项必须建立在与AWS(Linux)中的目标系统具有相同体系结构的系统上.

This functionality really is missing. You'll need to write your own packaging. Keep in mind that lambda dependencies must be built on a system with the same architecture as the target system in AWS (Linux) if any of the dependencies (such as Numpy) uses a shared library with native C code.

有一个可用的Docker映像,旨在提供一个尽可能接近AWS的环境:lambci/lambda:build-python3.7

There's a Docker image available which aims to provide an environment as close to AWS as possible: lambci/lambda:build-python3.7

因此,如果您要在任何非Linux体系结构上构建,则可能需要一些更复杂的lambda函数.

So if you're building on any non-Linux architecture, you might need this for some more complex lambda functions.

我为lambda打包开源了我的Python代码: https://gitlab.com/josef.stach/aws-cdk-lambda-asset

I opensourced my Python code for lambda packaging: https://gitlab.com/josef.stach/aws-cdk-lambda-asset