sudhir tataraju
sudhir tataraju

Reputation: 1379

How to deploy Java Lambda jar using Python CDK code?

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.

Upvotes: 2

Views: 1351

Answers (1)

Balu Vyamajala
Balu Vyamajala

Reputation: 10333

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)
    )
    

Upvotes: 2

Related Questions