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

java: Lambda Code.asset does not recognize jar as a zip file #1294

Closed
thesurlydev opened this issue Dec 5, 2018 · 5 comments
Closed

java: Lambda Code.asset does not recognize jar as a zip file #1294

thesurlydev opened this issue Dec 5, 2018 · 5 comments
Labels
@aws-cdk/assets Related to the @aws-cdk/assets package bug This issue is a bug.

Comments

@thesurlydev
Copy link
Contributor

thesurlydev commented Dec 5, 2018

I attempted to create a Lambda function and passing a path to a jar file to the withCode and got an exception: Asset must be a .zip file or a directory.

The asset validation should pass if the path points to a valid jar file (which is essentially a zip file).

As a workaround I found that by simply renaming the file from app.jar to app.zip gets past the validation.

@eladb
Copy link
Contributor

eladb commented Dec 5, 2018

Are you using lambda.Code.asset(file)?
Can you paste a code snippet?

@thesurlydev
Copy link
Contributor Author

Sure, here's the snippet:

        Code codeFromLocalPath = Code.asset("/Users/switbe/projects/app/app-0.1.jar");

        Function func = new Function(this, "test-func-cdk", FunctionProps.builder()
            .withCode(codeFromLocalPath)
            .withHandler("com.myorg.MyFunction::handle")
            .withMemorySize(512)
            .withTimeout(60)
            .withRole(role)
            .withRuntime(Runtime.JAVA8)
            .build());

If I rename the jar file to app-0.1.zip, change the asset path above to match and rerun synthesize the validation passes.

@thesurlydev
Copy link
Contributor Author

Looking at CDK code, a quick fix would be to update the following to also accept jar extension: https://github.com/awslabs/aws-cdk/blob/master/packages/%40aws-cdk/assets/lib/asset.ts#L93

@eladb
Copy link
Contributor

eladb commented Dec 5, 2018

Yes, makes sense. Thanks for reporting, I misread the original description that the problem is that JARs are not supported.

@thesurlydev
Copy link
Contributor Author

I'll be glad to contribute the fix for this. I'll have a PR in the next couple of days.

@rix0rrr rix0rrr added bug This issue is a bug. @aws-cdk/assets Related to the @aws-cdk/assets package labels Dec 10, 2018
@eladb eladb closed this as completed in 3076070 Dec 12, 2018
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.
Projects
None yet
Development

No branches or pull requests

3 participants