1

I am trying to deploy backend serverless resources with CDK in AWS cloud but getting errors while deploying things via GitLab build. trying with a local visual studio it works fine.

error is below :

$ npm run deploy-backend
> ui-dashboard-infra@0.0.0 deploy-backend /builds/project/control-panel/infra
> cdk deploy --app 'ts-node stacks/backend' --all --require-approval never
Bundling asset dashboard-A/restFunctionFallbackus-east-1/Code/Stage...
/builds/project/control-panel/infra/node_modules/@aws-cdk/core/lib/asset-staging.ts:398
      throw new Error(`Failed to bundle asset ${this.node.path}, bundle output is located at ${bundleErrorDir}: ${err}`);
            ^
Error: Failed to bundle asset dashboard-A/restFunctionFallbackus-east-1/Code/Stage, bundle output is located at /builds/project/control-panel/infra/cdk.out/bundling-temp-4607286efdd890681baca6f8a5d9b9b32929fa84e9947500fbe203e5b5d06a0f-error: Error: spawnSync bash ENOENT
    at AssetStaging.bundle (/builds/project/control-panel/infra/node_modules/@aws-cdk/core/lib/asset-staging.ts:398:13)
    at AssetStaging.stageByBundling (/builds/project/control-panel/infra/node_modules/@aws-cdk/core/lib/asset-staging.ts:246:10)
    at stageThisAsset (/builds/project/control-panel/infra/node_modules/@aws-cdk/core/lib/asset-staging.ts:137:35)
    at Cache.obtain (/builds/project/control-panel/infra/node_modules/@aws-cdk/core/lib/private/cache.ts:24:13)
    at new AssetStaging (/builds/project/control-panel/infra/node_modules/@aws-cdk/core/lib/asset-staging.ts:162:44)
    at new Asset (/builds/project/control-panel/infra/node_modules/@aws-cdk/aws-s3-assets/lib/asset.ts:68:21)
    at AssetCode.bind (/builds/project/control-panel/infra/node_modules/@aws-cdk/aws-lambda/lib/code.ts:180:20)
 
Subprocess exited with error 1
npm ERR! code ELIFECYCLE
npm ERR! errno 1
npm ERR! ui-dashboard-infra@0.0.0 deploy-backend: `cdk deploy --app 'ts-node stacks/backend' --all --require-approval never`
npm ERR! Exit status 1
npm ERR! 
npm ERR! Failed at the ui-dashboard-infra@0.0.0 deploy-backend script.
npm ERR! This is probably not a problem with npm. There is likely additional logging output above.
npm ERR! A complete log of this run can be found in:
npm ERR!     /root/.npm/_logs/2021-08-10T08_29_17_449Z-debug.log
Vadim Kotov
  • 8,084
  • 8
  • 48
  • 62
  • Do you get the same error if you try to execute from outside of npm context? ( `$(npm bin)/cdk deploy --app 'ts-node stacks/backend' --all --require-approval never` ) – Bartlomiej Nogas Feb 03 '22 at 15:57

2 Answers2

3

I got the same error as you. In my case, the issue was that I had esbuild installed as a dependency in the CDK folder, but not in the folder of my Lambda function.

I was able to fix the issue by installing esbuild as a dev dependency in my Lambda function folder. If you don't want to do that, you can also install it globally in your pipeline by adding the command npm i -g esbuild to your pipeline (consider pinning it to a particular version ie. npm i -g esbuild@x.y.z).

No idea why it was working locally without esbuild installed in the function folder, but then broke when doing the same thing in a Gitlab pipeline… I didn't have esbuild installed globally on my local machine or anything.

Ethan
  • 3,410
  • 1
  • 28
  • 49
2

I have faced a similar kind of issue, and the problem is that there is a bug in cdk versions prior to the once released before 25th Feb 2021.

For that, please make sure either you are using the latest version of cdk, or you DO NOT HAVE ANY WHITE SPACES IN YOUR FILE PATHNAME (any directory name having space or your username that has a space might cause this problem). Once I removed the white spaces from the pathname, everything started to work as expected.

Aamir Iqubal
  • 300
  • 2
  • 11