I am currently attempting to deploy an AWS CDK application on AWS CodePipeline using CodeBuild actions.
While the build and deploy processes run smoothly locally (as expected), encountering an issue when running on CodeBuild where the cdk
command fails with:
Cannot find module './index'
Subprocess exited with error 1
Despite its likely trivial nature, I can't seem to pinpoint the exact cause!
The project structure is auto-generated using cdk init --language typescript
<>/cdk$ ls
README.md app cdk.context.json cdk.json cdk.out jest.config.js lib node_modules package.json test tsconfig.json yarn.lock
The buildspec.yml
for the Build
stage consists of:
phases:
build:
commands:
- cd ${CODEBUILD_SRC_DIR}/cdk
- yarn install
- yarn build
artifacts:
base-directory: ${CODEBUILD_SRC_DIR}/cdk
files:
- '**/*'
The buildspec.yml
for the Deploy
stage (where the input directory is the artifact from the Build
stage i.e. the cdk
directory) looks like:
phases:
install:
commands:
- npm install -g aws-cdk
- cdk --version
build:
commands:
- cd ${CODEBUILD_SRC_DIR} # this is the cdk directory
- cdk ls
- cdk deploy app
During the Deploy
stage, the Cannot find module './index'
error occurs at the cdk ls
step. Since the local build/deploy steps work flawlessly (in a clean checkout), the issue seems related to copying artifacts from the Build
to Deploy
stages. However, I'm having trouble identifying the exact problem. Any suggestions for troubleshooting?