question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

[aws-lambda-python] Automatic bundling failing for PythonFunction

See original GitHub issue

The Question

PythonFunction won’t bundle files when executing cdk synth.

I created a simple project to demonstrate this and have attached. It’s basically a project created cdk init in python with an invocation of PythonFunction in the stack.py file.

test-aws-lambda-python-2.zip

The error I get when executing “cdk synth” is not very descriptive. Executing cdk synth with the “–verbose” and “–trace” options don’t reveal much either. I can surmise something is going wrong with building the Docker image, but I can’t determine the exact Docker build command used and it doesn’t return a detailed stack trace as to why the Docker build failed.

$ cdk synth
unable to prepare context: unable to evaluate symlinks in Dockerfile path: lstat /tmp/jsii-kernel-oyassh: no such file or directory
jsii.errors.JavaScriptError: 
  Error: docker exited with status 1
      at dockerExec (/tmp/jsii-kernel-oyassh/node_modules/@aws-cdk/core/lib/bundling.js:164:15)
      at Function.fromAsset (/tmp/jsii-kernel-oyassh/node_modules/@aws-cdk/core/lib/bundling.js:50:9)
      at Object.bundle (/tmp/jsii-kernel-oyassh/node_modules/@aws-cdk/aws-lambda-python/lib/bundling.js:33:43)
      at new PythonFunction (/tmp/jsii-kernel-oyassh/node_modules/@aws-cdk/aws-lambda-python/lib/function.js:39:30)
      at /tmp/tmp3c4u0sd1/lib/program.js:2720:58
      at Kernel._wrapSandboxCode (/tmp/tmp3c4u0sd1/lib/program.js:3148:24)
      at Kernel._create (/tmp/tmp3c4u0sd1/lib/program.js:2720:34)
      at Kernel.create (/tmp/tmp3c4u0sd1/lib/program.js:2461:29)
      at KernelHost.processRequest (/tmp/tmp3c4u0sd1/lib/program.js:9457:36)
      at KernelHost.run (/tmp/tmp3c4u0sd1/lib/program.js:9420:22)

The above exception was the direct cause of the following exception:

Traceback (most recent call last):
  File "app.py", line 9, in <module>
    TestAwsLambdaPython2Stack(app, "test-aws-lambda-python-2")
  File "/home/my_username/PycharmProjects/test-aws-lambda-python-2/.venv/lib/python3.6/site-packages/jsii/_runtime.py", line 83, in __call__
    inst = super().__call__(*args, **kwargs)
  File "/home/my_username/PycharmProjects/test-aws-lambda-python-2/test_aws_lambda_python_2/test_aws_lambda_python_2_stack.py", line 14, in __init__
    handler="handler", runtime=aws_lambda.Runtime.PYTHON_3_6)
  File "/home/my_username/PycharmProjects/test-aws-lambda-python-2/.venv/lib/python3.6/site-packages/jsii/_runtime.py", line 83, in __call__
    inst = super().__call__(*args, **kwargs)
  File "/home/my_username/PycharmProjects/test-aws-lambda-python-2/.venv/lib/python3.6/site-packages/aws_cdk/aws_lambda_python/__init__.py", line 243, in __init__
    jsii.create(PythonFunction, self, [scope, id, props])
  File "/home/my_username/PycharmProjects/test-aws-lambda-python-2/.venv/lib/python3.6/site-packages/jsii/_kernel/__init__.py", line 272, in create
    for iface in getattr(klass, "__jsii_ifaces__", [])
  File "/home/my_username/PycharmProjects/test-aws-lambda-python-2/.venv/lib/python3.6/site-packages/jsii/_kernel/providers/process.py", line 348, in create
    return self._process.send(request, CreateResponse)
  File "/home/my_username/PycharmProjects/test-aws-lambda-python-2/.venv/lib/python3.6/site-packages/jsii/_kernel/providers/process.py", line 330, in send
    raise JSIIError(resp.error) from JavaScriptError(resp.stack)
jsii.errors.JSIIError: docker exited with status 1
Subprocess exited with error 1
`

Environment

  • CDK CLI Version: 1.91.0
  • Module Version: 1.91.0
  • Node.js Version: v12.15.0
  • OS: Ubuntu 18.04.5 LTS
  • Language (Version): Python 3.6.9
  • Docker: 19.03.13, build cd8016b6bc (note, this is installed from snap)

Other information

Related issue: possibly https://github.com/aws/aws-cdk/issues/9349

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Comments:8 (4 by maintainers)

github_iconTop GitHub Comments

1reaction
lsli8888commented, Jul 9, 2021

@peterwoodworth Sorry for the late reply. Sorry, I’m not familiar or knowledgeable enough with Snap to know where it even has a temp directory. The error I saw didn’t give have enough logs to help me diagnose the issue that @misterjoshua might have. But it would definitely be nice if this issue could be fixed though!

0reactions
github-actions[bot]commented, Jul 20, 2021

⚠️COMMENT VISIBILITY WARNING⚠️

Comments on closed issues are hard for our team to see. If you need more assistance, please either tag a team member or open a new issue that references this one. If you wish to keep having a conversation with other community members under this issue feel free to do so.

Read more comments on GitHub >

github_iconTop Results From Across the Web

class PythonFunction (construct) · AWS CDK
It controls the permissions that the function will have. The Role must be assumable by the 'lambda.amazonaws.com' service principal. The default Role ...
Read more >
How to deploy Python AWS Lambda with its dependencies ...
Use the aws-cdk.aws-lambda-python L2 construct, it installs the dependencies automatically. Here's the documentation:.
Read more >
@aws-cdk/aws-lambda-nodejs | Yarn - Package Manager
The NodejsFunction construct creates a Lambda function with automatic transpiling and bundling of TypeScript or Javascript code.
Read more >
AWS Lambda Python - Lumigo
Boto3 comes with several other service-specific features, such as automatic multi-part transfers for Amazon S3 and simplified query conditions for DynamoDB.
Read more >
How to Set Up a CI/CD Pipeline for AWS Lambda With GitHub ...
Automatically deploy your Python function with dependencies in less than five ... It automatically bundles requirements from a requirements.txt and makes ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found