Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Failed to bundle asset error with CDK + Lambda

I have this project structure (where control is the name and root of my project):

control
|_ src
  |_ control_loader -> this has a function inside called also control_loader
  |_ utils
     |_ some_helper_function.py
     |_ __init__.py
  |_ __init__.py
|_ lib
   |_ some-cdk-where-i-declare-a-lambda.ts
|_ requirements.txt

Inside some-cdk-where-i-declare-a-lambda.ts I have this (among all the other necessary stuff):

        new Function(this, `${this.appName}${this.stageName}ControlLambdaLoader`, {
            code: Code.fromAsset(path.join(__dirname, '../src'), {
                bundling: {
                    image: Runtime.PYTHON_3_8.bundlingImage,
                    command: [
                        'bash', '-c',
                        'pip install -r requirements.txt -t /asset-output && cp -au . /asset-output',
                    ],
                },
            }),
            runtime: Runtime.PYTHON_3_8,
            handler: 'control_loader.control_loader',
            vpc,
            vpcSubnets: vpc.selectSubnets({
                subnetType: SubnetType.PRIVATE_WITH_NAT,
            }),
        });

However, upon running cdk synth, I get the following:

(venv) PS C:\Users\rodri\Documents\control> cdk synth
npx: installed 15 in 1.145s
Bundling asset controlPipelineStack/controlBetaDeployStage/controlbetaStack/controlbeta/controlbetaControlLambdaLoader/Code/Stage...
Failed to bundle asset controlPipelineStack/controlBetaDeployStage/controlbetaStack/controlbeta/controlbetaControlLambdaLoader/Code/Stage, bundle output is located at C:\Users\rodri\Documents\control\cdk.out\asset.059c3b383943a1fadd3d933b670a7d351991e742d24a9785474b35c846267fde-error: Error: spawnSync docker EN
OENT

This is a very cryptic error. I know the bundling is done by docker to push the dependencies as a zip asset, but, any idea of where is this failing? I also tried to change the location of requirements.txt to inside src and that didn't help. I can deploy everything I remove the Lambda out. What am I doing wrong? Also, how do I make the bundle include some_helper_function.py as well?

Thanks!

like image 215
rodrigocf Avatar asked Jul 01 '26 12:07

rodrigocf


1 Answers

I faced the same problem for a .net based cdk project. I didn't have my docker daemon running locally. When I started the docker agent, I got this successfully running.

like image 56
user007 Avatar answered Jul 05 '26 18:07

user007



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!