aws cloudformation package after prune fails

Viewed 113

I have an application in NodeJS which I am building with AWS CodeBuild and then deploying using AWS Cloudformation to AWS lambda. In my buildspec.yaml I install the node application and run tests and then, before issuing the aws cloudformation packagecommand I perform a prune command so that only production dependencies remain:

npm prune --production

When I issue the aws cloudformation package command it fails with the following error:

Error: Unable to upload artifact nodejs/. referenced by ContentUri parameter of CommonLayer resource.
[Errno 2] No such file or directory: '/codebuild/output/src609569331/src/common/nodejs/node_modules/.bin/watch'

My buildspec file:

version: 0.2

phases:
    install:
        runtime-versions:
            nodejs: 12.x
        commands:
            - echo INSTALL STARTED on `date`
            - cd common/nodejs
            - npm install -g npm
            - npm ci

            # Prevent files from having a timestamp before 1980!!!
            # Without this the build fails with "zip does not support timestamps before 1980"!
            - find ./node_modules -mtime +10950 -exec touch {} \;

            # Upgrade AWS CLI to the latest version
            - pip install --upgrade awscli
            - echo INSTALL COMPLETED on `date`

    pre_build:
        commands:
            - echo PRE_BUILD STARTED on `date`
            - npm run lint
            - npm test
            - npm prune --production
            - cd ..
            - echo PRE_BUILD COMPLETED on `date`

    build:
        commands:
            - echo BUILD STARTED on `date`
            - aws cloudformation package --template-file lambda-template.yaml
                --output-template-file packaged-common-deployment.yaml
                --s3-bucket "${BUILD_BUCKET}"
            - echo BUILD COMPLETED on `date`

artifacts:
    type: zip
    files:
        - "**/*"
    base-directory: common
    discard-paths: no
0 Answers
Related