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

(software.amazon.awscdk.services.lambda.Function): Recursive folder creation in cdk.out when lambda jar path is mentioned as "" #29410

Closed
lohithsamaga opened this issue Mar 8, 2024 · 2 comments · Fixed by #29425
Labels
@aws-cdk/aws-lambda Related to AWS Lambda bug This issue is a bug. effort/small Small work item – less than a day of effort p2

Comments

@lohithsamaga
Copy link

Describe the bug

When creating a lambda function using CDK Java, if the lambda jar file path mentioned as "" in the Code parameter, the synth/diff/deploy process initiates an infinite recursive creation of directories "cdk.out/asset-xxx/cdk.out/asset-xxx/,,,".
It throws an error at the end when the file path is too deep. There is no warning if the asset folder is not mentioned.
Also this leads to a blue screen when the project is opened in Eclipse.

Please fix this issue.

Expected Behavior

Throw an error that the asset path is not provided.

Current Behavior

Creation of infinite nested folders.

Reproduction Steps

FunctionProps props = FunctionProps.builder()
    	.code(Code.fromAsset(""))
    	.handler("com.example.action.handler.MyAction")
    	.functionName("MyFunction")
    	.runtime(Runtime.JAVA_11)
    	.logRetention(RetentionDays.ONE_WEEK)
    	.role(f1Role)
    	.build();
	
	Function f1 = new Function(this,"Fun", props);

Possible Solution

Stop the synthesis and throw an error message that the asset path cannot be a zero-lenth string.

Additional Information/Context

No response

CDK CLI Version

2.102.0

Framework Version

2.102.0

Node.js Version

v18.16.0

OS

Windows 10

Language

Java

Language Version

11

Other information

No response

@lohithsamaga lohithsamaga added bug This issue is a bug. needs-triage This issue or PR still needs to be triaged. labels Mar 8, 2024
@github-actions github-actions bot added the @aws-cdk/aws-lambda Related to AWS Lambda label Mar 8, 2024
@pahud pahud added p2 effort/medium Medium work item – several days of effort effort/small Small work item – less than a day of effort and removed needs-triage This issue or PR still needs to be triaged. effort/medium Medium work item – several days of effort labels Mar 8, 2024
@pahud
Copy link
Contributor

pahud commented Mar 8, 2024

Yes we should check if the asset path exists.

@mergify mergify bot closed this as completed in #29425 Apr 4, 2024
mergify bot pushed a commit that referenced this issue Apr 4, 2024
### Issue # (if applicable)

Closes #29410.

### Reason for this change

It was reported that a `Code.fromAsset('')` was creating an infinite loop by including itself through `cdk.out`. This is caused by the following line:

https://github.com/aws/aws-cdk/blob/730fe63efc461c14f6e2b4aa9206c10f9b0f4cd9/packages/aws-cdk-lib/aws-s3-assets/lib/asset.ts#L145

If an empty string is given to `path.resolve()`, the current working directory is returned.

### Description of changes

I've added a check that verifies that the given `path` property is not empty.

### Description of how you validated changes

I've added a test for both the `aws-lambda` package, where the issue was originally reported, and `aws-s3-assets`, where the fix was implemented

### Checklist
- [x] My code adheres to the [CONTRIBUTING GUIDE](https://github.com/aws/aws-cdk/blob/main/CONTRIBUTING.md) and [DESIGN GUIDELINES](https://github.com/aws/aws-cdk/blob/main/docs/DESIGN_GUIDELINES.md)

----

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

github-actions bot commented Apr 4, 2024

⚠️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
@aws-cdk/aws-lambda Related to AWS Lambda bug This issue is a bug. effort/small Small work item – less than a day of effort p2
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants