Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[aws-lambda] Bundling code fails with Docker error 125 (wrong flag provided) starting from 1.61.0 #10262

Closed
jarikujansuu opened this issue Sep 9, 2020 · 4 comments · Fixed by #10620
Assignees
Labels
@aws-cdk/assets Related to the @aws-cdk/assets package bug This issue is a bug. effort/small Small work item – less than a day of effort p1

Comments

@jarikujansuu
Copy link

jarikujansuu commented Sep 9, 2020

When trying to run tests that contain Lambda get error with Docker code 125. Tested different versions from 1.55.0 to current 1.62.0 and error seems to appear in 1.61.0

Running Docker version 19.03.12, build 48a66213fe on MacOS 10.14.6

Failed to bundle asset MyTestStack/DeltaHandler/Code/Stage, bundle output is located at /var/folders/q6/myync74s6y3d56dsbdt4xtgh0000gn/T/cdk.outfhCgSf/asset.96d820282efdb1403c735a823a6797110cd117197eca021f6037be7bed0cf9d2-error: Error: docker exited with status 125

Reproduction Steps

PythonFunction wrapper might be unnecessary in newer versions but it was when submitted earlier bug about it. Of course needs something in Lambda directory too.

import '@aws-cdk/assert/jest';
import { Code, Function, Runtime } from '@aws-cdk/aws-lambda';
import { App, AssetStaging, Construct, Stack } from '@aws-cdk/core';
import { PythonFunctionProps } from '../cdk/lib/lambda/PythonFunction';

export class PythonFunction extends Function {
  constructor(scope: Construct, id: string, props: PythonFunctionProps) {
    super(scope, id, {
      ...props,
      code: Code.fromAsset(props.path, {
        bundling: {
          image: props.runtime.bundlingDockerImage,
          command: [
            'bash',
            '-c',
            PythonFunction.chain([
              `pip install -r requirements.txt -t ${AssetStaging.BUNDLING_OUTPUT_DIR}`,
              `cp -R . ${AssetStaging.BUNDLING_OUTPUT_DIR}`,
            ]),
          ],
        },
      }),
    });
  }

  static chain(commands: string[]): string {
    return commands.filter(c => !!c).join(' && ');
  }
}


describe('Test', () => {
  const app = new App();
  const stack = new Stack(app, 'MyTestStack');
  new PythonFunction(stack, 'Function', {
    runtime: Runtime.PYTHON_3_8,
    handler: 'handler.handle',
    path: './lambda/delta-sync',
  });

  test('Test', () => {
    expect(stack).toHaveResource('AWS::Lambda::Function', {
      Runtime: 'python3.8',
    })
  });
});

What did you expect to happen?

Test should run and lambda should be bundled using Docker.

What actually happened?

Failed to bundle asset MyTestStack/Function/Code/Stage, bundle output is located at /var/folders/q6/myync74s6y3d56dsbdt4xtgh0000gn/T/cdk.outVZd5d7/asset.96d820282efdb1403c735a823a6797110cd117197eca021f6037be7bed0cf9d2-error: Error: docker exited with status 125

Environment

  • CLI Version :
  • **Framework Version: error appears in 1.61.0
  • Node.js Version: v14.7.0
  • **OS : macOs
  • Language (Version): TypeScript (3.8.3)

Other


This is 🐛 Bug Report

@jarikujansuu jarikujansuu added bug This issue is a bug. needs-triage This issue or PR still needs to be triaged. labels Sep 9, 2020
@github-actions github-actions bot added the @aws-cdk/aws-lambda Related to AWS Lambda label Sep 9, 2020
@nija-at nija-at added @aws-cdk/assets Related to the @aws-cdk/assets package and removed @aws-cdk/aws-lambda Related to AWS Lambda labels Sep 9, 2020
@nija-at nija-at assigned eladb and unassigned nija-at Sep 9, 2020
@eladb
Copy link
Contributor

eladb commented Sep 21, 2020

@jogold can you take a look?

@eladb eladb added effort/small Small work item – less than a day of effort p1 labels Sep 21, 2020
@jogold
Copy link
Contributor

jogold commented Sep 21, 2020

@jarikujansuu

What happens when you specify an outdir in your test?

describe('Test', () => {
  const app = new App({
    outdir: './cdk.out' // <-- this
  });
});

and then can you try replacing os.tmpdir() with fs.realpathSync(os.tmpdir()) here?

return outdir ?? fs.mkdtempSync(path.join(os.tmpdir(), 'cdk.out'));

or replace the file at node_modules/@aws-cdk/cx-api/lib/cloud-assembly.js with this gist: https://gist.github.com/jogold/09a0aca5f62c4373d2e55054d318e686

@SomayaB SomayaB removed the needs-triage This issue or PR still needs to be triaged. label Sep 21, 2020
@jogold
Copy link
Contributor

jogold commented Sep 24, 2020

@jarikujansuu have you been able to try it?

jogold added a commit to jogold/aws-cdk that referenced this issue Oct 1, 2020
When running unit tests `outdir` defaults to a temporary directory in
the system temp directory. On macOS `os.tmpdir()` is a symlink so
bundling in Docker fails.

Fix it by using `fs.realpathSync`.

Closes aws#10262
@mergify mergify bot closed this as completed in #10620 Oct 1, 2020
mergify bot pushed a commit that referenced this issue Oct 1, 2020
When running unit tests `outdir` defaults to a temporary directory in
the system temp directory. On macOS `os.tmpdir()` is a symlink. In 
`v1.61.0` we changed the bundling directory to be a directory inside
`outdir` (`cdk.out`). This makes Docker bundling fail during tests.

Fix it by using `fs.realpathSync`.

Closes #10262


----

*By submitting this pull request, I confirm that my contribution is made under the terms of the Apache-2.0 license*
@joysl
Copy link

joysl commented Jul 9, 2021

Hi,
I get the same error: /git-code/lex_sf_drug_regminder_blog/cdk.out/asset.22e85c5c2352db3d74d8ca44d3e60507511b798ba9b44cdd153fd302a28b4968-error: Error: docker exited with status 125
CDK Version: 1.111.0

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
@aws-cdk/assets Related to the @aws-cdk/assets package bug This issue is a bug. effort/small Small work item – less than a day of effort p1
Projects
None yet
Development

Successfully merging a pull request may close this issue.

6 participants