2

Can any one help me with syntax to deploy a Java Lambda using Python CDK code? Below is the python CDK code snippet Iam using to deploy Python written Lambda.

handler = lmb.Function(self, 'Handler',
        runtime=lmb.Runtime.PYTHON_3_7,
        handler='handler.handler',
        code=lmb.Code.from_asset(path.join(this_dir, 'lambda')))

And below is the Java CDK code snippet my colleague using:

Function javafunc = new Function(this, CommonFunctions.getPropValues("HANDLER"), 
FunctionProps.builder()
            .runtime(Runtime.JAVA_8)
            .handler(CommonFunctions.getPropValues("Java_LAMBDA"))
            .code(Code.fromAsset(tmpBinDir + "/"+CommonFunctions.getPropValues("JAR_FILE_NAME")))
            .timeout(Duration.seconds(300))
            .memorySize(512)
            .functionName(CommonFunctions.getPropValues("FUNCTION_NAME"))
            .build());

I don't know Java and I have requirement to deploy Java compiled Lambda jar using Python CDK.

1 Answer 1

2

We need these imports

from aws_cdk import (
    core,
    aws_lambda,
)

code: jar file path handler: mainClassName::methodName

    aws_lambda.Function(
        self, "MyLambda",
        code=aws_lambda.Code.from_asset(path='javaProjects/path/to/jar/my-lambda-1.0.jar'),
        handler='com.test.handler.StreamLambdaHandler::handleRequest',
        runtime=aws_lambda.Runtime.JAVA_11,
        environment={
            'ENV_APPLICATION_NAME': 'anyValue')
        },
        memory_size=1024,
        timeout=core.Duration.seconds(30)
    )
    
Sign up to request clarification or add additional context in comments.

1 Comment

Thanks a lot @Balu Vyamajala it worked perfectly. another way is since jar is nothing but a zip file I extracted and copied to lambda folder the aws_lambda.Code.from_asset refering.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.