Aws-cdk: Asset building uses incorrect temp folder on mac

Created on 10 Jun 2020  路  4Comments  路  Source: aws/aws-cdk

Building assets on macOS uses a temp folder that is not accessible on the mac. The folder /var/folders is protected. The correct folder on macOS is /private/var/folders

Reproduction Steps

    const assetPath = path.join(__dirname, 'python-lambda-handler');
    const fn = new lambda.Function(this, 'Function', {
      code: lambda.Code.fromAsset(assetPath, {

        bundling: {
          image: lambda.Runtime.PYTHON_3_6.bundlingDockerImage,
          command: [
            'bash', '-c', [
              'rsync -r . /asset-output',
              'cd /asset-output',
              'pip install -r requirements.txt -t .',
            ].join(' && '),
          ],
        },
      }),
      runtime: lambda.Runtime.PYTHON_3_6,
      handler: 'index.handler',
    });

Error Log

stderr: docker: Error response from daemon: Mounts denied:
The path /var/folders/51/82x5pt6s7_l8rymy5gqpf5dr0000gn/T/cdk-asset-bundle-aePfzr
is not shared from OS X and is not known to Docker.
You can configure shared paths from Docker -> Preferences... -> File Sharing.
See https://docs.docker.com/docker-for-mac/osxfs/#namespaces for more info.

Environment

  • **CLI Version : 1.45.0
  • **Framework Version: 1.45.0
  • **Node.js Version: 14.4.0
  • **OS : macOS
  • **Language (Version): Typescript

Other

To solve the error the correct temp directory should be set. The npm package temp-dir can fix this error.

The file asset-staging.js
const bundleDir = fs.mkdtempSync(path.resolve(path.join(os.tmpdir(), 'cdk-asset-bundle-')));
should then be changed in:
const bundleDir = fs.mkdtempSync(path.resolve(path.join(require('temp-dir'), 'cdk-asset-bundle-')));


This is :bug: Bug Report

bug needs-triage

Most helpful comment

This seems not to be fixed. Bundling assets as part of NodeJsFunction still uses a temp folder under /var/folders (CDK v1.61.0)

All 4 comments

OK, temp-dir just does fs.realpathSync(os.tmpdir()), will fix this.

This seems not to be fixed. Bundling assets as part of NodeJsFunction still uses a temp folder under /var/folders (CDK v1.61.0)

I got the same problem as @pgarbe mentioned on 1.63.0.
As a work-around added folder as shared resource: Docker -> Preferences -> Resources -> File Sharing -> /var/folders/ng/XXXXXYYYYYZZZZZ/

I'm also having this same problem:

docker: Error response from daemon: Mounts denied:
The path /var/folders/w4/8ykdwb4j1cqdmppn9_4mn_lw0000gn/T/cdk.outIbEgm6/bundling-temp-KhjHwV
is not shared from OS X and is not known to Docker.

But only when run tests. Bundling when synthesizing works.

I was also able to get past it by sharing /var/folders with docker.

Was this page helpful?
0 / 5 - 0 ratings