How to install dependencies of lambda functions upon cdk build wtih AWS CDK

佐手、 提交于 2019-12-10 04:21:21

问题


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).

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


回答1:


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.

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

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

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




回答2:


It does not do it automatically You'll need to package those. Then you'll be able to use fromAsset or fromBucket to get connect the code to the function



来源:https://stackoverflow.com/questions/57197258/how-to-install-dependencies-of-lambda-functions-upon-cdk-build-wtih-aws-cdk

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!