All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.github.seanroy.plugins.UpdateLambdaCodeMojo Maven / Gradle / Ivy

There is a newer version: 2.3.5
Show newest version
package com.github.seanroy.plugins;

import com.amazonaws.services.lambda.model.GetFunctionRequest;
import com.amazonaws.services.lambda.model.ResourceNotFoundException;
import org.apache.maven.plugin.MojoExecutionException;
import org.apache.maven.plugins.annotations.Mojo;

import java.util.function.Function;

/**
 * I am a update code mojo responsible to update lambda function code in AWS.
 *
 * @author Joseph Wortmann, Joseph Wortmann 2/1/2018.
 */
@Mojo(name = "update-lambda-code")
public class UpdateLambdaCodeMojo extends AbstractLambdaMojo {

    @Override
    public void execute() throws MojoExecutionException {
        super.execute();
        try {
            uploadJarToS3();
            lambdaFunctions.stream().map(f -> {
                getLog().info("---- Update function code " + f.getFunctionName() + " -----");
                return f;
            }).forEach(lf -> updateFunctionCodeIfExists.apply(lf));
        } catch (Exception e) {
            getLog().error("Error during processing", e);
            throw new MojoExecutionException(e.getMessage());
        }
    }

    private Function updateFunctionCodeIfExists = (LambdaFunction lambdaFunction) -> {
        try {
            lambdaFunction.setFunctionArn(lambdaClient.getFunction(
                    new GetFunctionRequest().withFunctionName(lambdaFunction.getFunctionName())).getConfiguration().getFunctionArn());
            updateFunctionCode.apply(lambdaFunction);
        } catch (ResourceNotFoundException e) {
            getLog().info("Lambda function not found", e);
        }
        return lambdaFunction;
    };
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy