简体   繁体   中英

How to reuse the code in all aws lambda function?

Programming Language - Java

We have 10 different aws lambda function. here we need to have same functionality for all the 10 lambda function. Instead of duplicating the same functionality 10 time. We can create common functionality and packaging as a framework jar and call them in each aws lambda function.

My question is how and where to deploy the jar file in aws and how we can include that jar file in all lambda functions and how to call the particular function in aws lambda function.

Now that Lambda Layers are available you can use one Layer to share a jar file between multiple Lambda Functions.

Similarly to Lambda Functions you create Layers using a zip file. To share your custom code you'll need a zip file like follows:

my-layer.zip
└ java/lib/my-custom.jar

Then you can create your Lambda Functions on top of your custom layer and reference my-custom.jar as if it would be in your environment.

My approach is; you can make only one lambda function, and placed an API Gateway in front of it. With the params from API Gateway, you can parse the lambda.

In example;

1 - Your main lambda handler function is parsing the "extension" parameter

2 - API Gateway gets and sends "extension" parameter to Lambda

3 - Lambda checks if extension is xml, xmlParser() will work or if .jar jarParser will works.

So there is no need to make 10 lambda functions.

Best,

如果您使用的是node.js,那么这篇文章真的非常棒并且解释得非常好。

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM