HiveBrain v1.2.0
Get Started
← Back to all entries
snippetMinor

How can I deploy an AWS Lambda function from Jenkins?

Submitted by: @import:stackexchange-devops··
0
Viewed 0 times
canjenkinsfunctiondeployawshowfromlambda

Problem

I have a simple Lambda function that I'm trying to deploy through Jenkins -

public String handleRequest(String input, Context context) {
        String output = "";
        if (input.isEmpty()) {
            output = "No input provided";
        } else {
            output = "Hello, " + input + "! Checking invocation - 1";
        }
        return output;
    }


I'm able to deploy and invoke this through Eclipse's AWS Lambda plugin without any problems.

I'm using the AWS Lambda plugin for Jenkins and following their documentation.

  • I'm providing my Git repository as the source.



  • Artifact Location - src/main/java/



  • Handler Name - lambda.Hello (lambda is the package name and Hello is the class name). I've also tried using lambda.Hello.handleRequest, lambda.Hello::handleRequest and other variations.



Jenkins says that the build was successful but when I test it on the AWS console, I'm getting -

"errorMessage": "Class not found: lambda.Hello",
  "errorType": "class java.lang.ClassNotFoundException"


Where am I going wrong here? When I export the test function from AWS and unzip it, I can see that code on Git definitely got deployed but it's unable find the class.

Solution

I found the solution while trying to manually deploy the Lambda function as a jar file. These are the steps -

  • Create your Lambda function as a Maven project using the AWS documentation.



  • Create your Jenkins job as a Maven project and specify package in the goals section.



  • Follow the Jenkins Lambda plugin documentation for deployment and specify target/your-project-1.0-SNAPSHOT.jar as the Artifact location.



This should build your Lambda function with Maven and then deploy it to AWS.

Context

StackExchange DevOps Q#1469, answer score: 3

Revisions (0)

No revisions yet.