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-python): CDK synth fails while bundling asset for lambda function or layer #18430

Closed
lacteolus opened this issue Jan 14, 2022 · 4 comments
Assignees
Labels

Comments

@lacteolus
Copy link

lacteolus commented Jan 14, 2022

What is the problem?

CDK synth fails when aws_cdk.aws_lambda_python_alpha is used. It worked with 2.2. version but fails in 2.5 and 2.8. Maybe other versions are affected as well.
The problem seems to be in Windows environment only because it works in AWS Codebuild (aws/codebuild/standard:4.0 which is Ubuntu 18.04)

Reproduction Steps

Init CDK app:
cdk init app --language=python

Simple CDK app is created with a single stack.
'lambda_layer' - directory for lambda layer code
'lambda_code' - directory for lambda function code
'python_project1/python_project1_stack.py' file:

from aws_cdk import Stack
from constructs import Construct
from aws_cdk.aws_lambda_python_alpha import PythonLayerVersion, PythonFunction
from aws_cdk.aws_lambda import Runtime, Function, LayerVersion, Code

class PythonProject1Stack(Stack):

    def __init__(self, scope: Construct, construct_id: str, **kwargs) -> None:
        super().__init__(scope, construct_id, **kwargs)

        layer_path = 'lambda_layer'
        lambda_path = 'lambda_code'

        PythonLayerVersion(
            self,
            'Layer1',
            entry=layer_path,
            compatible_runtimes=[Runtime.PYTHON_3_9]
        )

        PythonFunction(
            self,
            'Function1',
            runtime=Runtime.PYTHON_3_9,
            handler="lambda_handler",
            index="index.py",
            entry=lambda_path,
        )

        LayerVersion(
            self,
            'Layer2',
            code=Code.from_asset(layer_path),
            compatible_runtimes=[Runtime.PYTHON_3_9]
        )

        Function(
            self,
            'Function2',
            code=Code.from_asset(lambda_path),
            runtime=Runtime.PYTHON_3_9,
            handler='index.lambda_handler',

        )

cdk synth --all is invoked to synthesize app.

An error is raised and synth fails. It fails for Layer1 and Function1 with similar errors.
But it works for Layer2 and Function2.

What did you expect to happen?

Synth process finishes successfully and assets are bundled for the app into cdk.out directory

What actually happened?

Bundling asset PythonProject1Stack/Layer1/Code/Stage...
cp: cannot copy a directory, ‘/asset-input/’, into itself, ‘asset-outputpython’
jsii.errors.JavaScriptError:
  Error: Failed to bundle asset PythonProject1Stack/Layer1/Code/Stage, bundle output is located at D:\Repositories\pythonProject1\cdk.out\asset.5470a3f49d3959d7cf18d599c13ca7a43389e2f9bfde4e13b42afb69b223e444-error: Error: docker exited with status 1
      at AssetStaging.bundle (C:\Users\User\AppData\Local\Temp\jsii-kernel-bUHYEs\node_modules\aws-cdk-lib\core\lib\asset-staging.js:2:672)
      at AssetStaging.stageByBundling (C:\Users\User\AppData\Local\Temp\jsii-kernel-bUHYEs\node_modules\aws-cdk-lib\core\lib\asset-staging.js:1:4168)
      at stageThisAsset (C:\Users\User\AppData\Local\Temp\jsii-kernel-bUHYEs\node_modules\aws-cdk-lib\core\lib\asset-staging.js:1:1675)
      at Cache.obtain (C:\Users\User\AppData\Local\Temp\jsii-kernel-bUHYEs\node_modules\aws-cdk-lib\core\lib\private\cache.js:1:242)
      at new AssetStaging (C:\Users\User\AppData\Local\Temp\jsii-kernel-bUHYEs\node_modules\aws-cdk-lib\core\lib\asset-staging.js:1:2070)
      at new Asset (C:\Users\User\AppData\Local\Temp\jsii-kernel-bUHYEs\node_modules\aws-cdk-lib\aws-s3-assets\lib\asset.js:1:620)
      at AssetCode.bind (C:\Users\User\AppData\Local\Temp\jsii-kernel-bUHYEs\node_modules\aws-cdk-lib\aws-lambda\lib\code.js:1:3503)
      at new LayerVersion (C:\Users\User\AppData\Local\Temp\jsii-kernel-bUHYEs\node_modules\aws-cdk-lib\aws-lambda\lib\layers.js:1:1239)
      at new PythonLayerVersion (C:\Users\User\AppData\Local\Temp\jsii-kernel-bUHYEs\node_modules\@aws-cdk\aws-lambda-python-alpha\lib\layer.js:35:9)
      at C:\Users\User\AppData\Local\Temp\tmp4t1cb_79\lib\program.js:8432:58

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

Traceback (most recent call last):
  File "D:\Repositories\pythonProject1\app.py", line 10, in <module>
    PythonProject1Stack(app, "PythonProject1Stack",
  File "D:\Repositories\pythonProject1\.venv\lib\site-packages\jsii\_runtime.py", line 86, in __call__
    inst = super().__call__(*args, **kwargs)
  File "D:\Repositories\pythonProject1\python_project1\python_project1_stack.py", line 15, in __init__
    PythonLayerVersion(
  File "D:\Repositories\pythonProject1\.venv\lib\site-packages\jsii\_runtime.py", line 86, in __call__
    inst = super().__call__(*args, **kwargs)
  File "D:\Repositories\pythonProject1\.venv\lib\site-packages\aws_cdk\aws_lambda_python_alpha\__init__.py", line 1263, in __init__
    jsii.create(self.__class__, self, [scope, id, props])
  File "D:\Repositories\pythonProject1\.venv\lib\site-packages\jsii\_kernel\__init__.py", line 290, in create
    response = self.provider.create(
  File "D:\Repositories\pythonProject1\.venv\lib\site-packages\jsii\_kernel\providers\process.py", line 344, in create
    return self._process.send(request, CreateResponse)
  File "D:\Repositories\pythonProject1\.venv\lib\site-packages\jsii\_kernel\providers\process.py", line 326, in send
    raise JSIIError(resp.error) from JavaScriptError(resp.stack)
jsii.errors.JSIIError: Failed to bundle asset PythonProject1Stack/Layer1/Code/Stage, bundle output is located at D:\Repositories\pythonProject1\cdk.out\asset.5470a3f49d3959d7cf18d599c13ca7a43389e2f9bfde4e13b42afb69b223e444-error: Error: docker exited
with status 1
Subprocess exited with error 1

CDK CLI Version

2.8

Framework Version

No response

Node.js Version

v16.5.0

OS

Windows 10

Language

Python

Language Version

3.9.6

Other information

No response

@lacteolus lacteolus added bug This issue is a bug. needs-triage This issue or PR still needs to be triaged. labels Jan 14, 2022
@github-actions github-actions bot added the @aws-cdk/aws-lambda Related to AWS Lambda label Jan 14, 2022
@lacteolus
Copy link
Author

Directory mentioned in error message - D:\Repositories\pythonProject1\cdk.out\asset.5470a3f49d3959d7cf18d599c13ca7a43389e2f9bfde4e13b42afb69b223e444-error
is empty

@ryparker ryparker added p2 and removed needs-triage This issue or PR still needs to be triaged. labels Jan 14, 2022
@kaizencc kaizencc added @aws-cdk/aws-lambda-python and removed @aws-cdk/aws-lambda Related to AWS Lambda labels Jan 21, 2022
@kaizencc kaizencc removed their assignment Feb 3, 2022
@tevans-submittable
Copy link

tevans-submittable commented Feb 10, 2022

Also worked in 1.136.0, but now failing in 1.144.0.

Edit: Narrowed it down to being introduced in 1.138.0

@corymhall
Copy link
Contributor

@lacteolus we are currently tracking this issue in #18861

@github-actions
Copy link

github-actions bot commented Mar 4, 2022

⚠️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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

5 participants