Gartner Blog Network


Calling a Python Function From Java

by Raj Bala  |  February 7, 2020  |  Submit a Comment

I spend a great deal of time thinking about serverless computing and what it means to application development, operations, etc.

But one of the most understated aspects from the perspective of a software developer is that I can mix and match programming languages and frameworks like never before.

Writing a Java application, but you want to take advantage of Python’s rich data science libraries? Invoke those Python capabilities using your choice of functions as a service (FaaS) platform!

The way you do this when using Python on AWS Lambda is like this:

response = client.invoke(
FunctionName='MyJavaFunction',
InvocationType='Event',
LogType='Tail',
ClientContext='string',
Payload=b'bytes',
Qualifier='string'
)

MyJavaFunction is another Lambda function that could be Java, Go, Ruby or whatever the platform supports. The Payload parameter is the other important part. Typically, I use byte-encoded JSON payloads that are minimal in size. The called function gets an event parameter with the byte-encoded JSON.

Want to do something similar on Azure? It’s called a Durable Function.

Ultimately, this is the benefit of single-purpose microservices. You can use the right tool for the right job rather than being constrained to one language, one framework or even one database.

Additional Resources

View Free, Relevant Gartner Research

Gartner's research helps you cut through the complexity and deliver the knowledge you need to make the right decisions quickly, and with confidence.

Read Free Gartner Research

Category: 

Tags: code  faas  

Raj Bala
Research Director
5 years at Gartner
20 years IT Industry

Raj Bala is a Research Director at Gartner covering cloud infrastructure and platform services. Read Full Bio




Leave a Reply

Your email address will not be published. Required fields are marked *

Comments or opinions expressed on this blog are those of the individual contributors only, and do not necessarily represent the views of Gartner, Inc. or its management. Readers may copy and redistribute blog postings on other blogs, or otherwise for private, non-commercial or journalistic purposes, with attribution to Gartner. This content may not be used for any other purposes in any other formats or media. The content on this blog is provided on an "as-is" basis. Gartner shall not be liable for any damages whatsoever arising out of the content or use of this blog.