lambda-maven-plugin
lambda-maven-plugin copied to clipboard
Using the plugin in a parent-child configuration
I'm trying to get this plugin working under a multimodule project, example structure:
services (root) -- service1 (child) -- service2 (child) -- service3 (child)
What I want to be able to do is to either go into one of the services and deploy it to lambda, or stand in the root and deploy all of them, using mvn package shade:shade lambda:deploy-lambda
.
I'm trying to set it up using pluginManagement but I'm miserably failing, whatever I do it tries to deploy my root module to AWS Lambda, while other plugins I use ignores the root project when the plugin is under <pluginManagement/>
tag.
So do you want something like the following?
mvn lambda:deploy-lambda // Deploy ALL lambda functions mvn lambda:deploy-lambda:function_name // Deploy only function_name
Something like this:
project maven module structure:
/lambda-functions (root)
-- /user-service
---- /create-user-lambda-function
---- /login-lambda-function
---- /logout-lambda-function
-- /cake-service
---- /eat-cake-lambda-function
cd lambda-functions/user-service && mvn lambda:deploy-lambda
would deploy create user, login, logout functions.
cd lambda-functions/user-service/login-lambda-function && mvn lambda:deploy-lambda
would deploy only the login function.
cd lambda-functions && mvn lambda:deploy-lambda
would deploy everything, recursively.
Previously (pre-lambda days) I've solved this by adding plugins in root pom (lambda-functions module), using <pluginManagement/>
in <build/>
. Then, I specify the individual properties in all the sub pom's in the lambda-function modules. This way I can use the same maven execution, and my position in the tree would decide what gets built and deployed. We tend to organize in tree structure for our projects and most vital plugins we use supports this.
Today I'm using a workaround with sh-script, which is a bit of pain to maintain, we're up to 130 functions now and counting. ;)
Does this make sense?
Thank you
OK, so is there just one uber JAR with all of your functions defined in it, or do you want maven to build a jar with just the functions at your CWD?
@kilsbo, I just downloaded the multi module project from the maven book site (https://books.sonatype.com/mvnex-book/reference/multimodule-sect-intro.html). I added the properties from my README.md to the simple-parent/pom.xml. Then I added the plugin block from my README.md to simple-weather/pom.xml. I copied the simple-weather directory to simple-weather-too and slightly modified it so that it would package properly and so that I'd have two separate lambda functions. I then deployed both functions by running mvn package shade:shade lambda:deploy-lambda -DsecretKey <SECRET> -DaccessKey <ACCESS>
Seems like you should be able to do the same thing.
Ah, I see, the part I'm missing is being able to do it from the root. To me this still has to be a maven thing rather than having anything to do with the plugin itself.
Hello, thank you for the attention to this.
Yes, exactly, from the root. To the best of my knowledge, maven approach for this is to put the plugin with global options set within the <pluginManagement/> tag in the root pom. After that I override individual settings in child poms in the
After this, I am normally able to run the build from the root, for instance i use the build number plugin to inject my git commit id's.
What I stumbled upon with this plugin was that it treated it as
This weekend I will double check this and paste in commands and output here together with my pom's, maybe I am missing something.
Until then, thank you.