Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Fixing JAR File Reference in AWS CodePipeline for Lambda Deployment

I am working on an AWS CodePipeline project where I want to build and deploy a Java Lambda function whenever there are changes to my source code repository. I have created Terraform configuration to deploy the Lambda function and upload the Java JAR file to it. This is working when I run Terraform locally, however when the CodePipeline executes, it fails with an error indicating it cannot find the target JAR file to upload to Lambda. I have tried using absolute paths, the path.module function, and other solutions for referencing the JAR file location but none have successfully allowed CodePipeline to locate the artifact.

The project structure consists of:

  • A root directory with main.tf containing a module block that calls the Terraform module code.
  • A /terraform-module directory with lambda.tf which contains the Lambda resource definition.
resource "aws_lambda_function" "java_lambda_function" {
  runtime          = "${var.lambda_runtime}"
  filename      = "${path.module}/../target/code.zip"
  source_code_hash = "${data.archive_file.lambda_archive.output_base64sha256}"
  function_name = "java_lambda_function"
  handler          = "${var.lambda_function_handler}"
  timeout = 60
  memory_size = 256
  role             = "${aws_iam_role.iam_role_for_lambda.arn}"
  depends_on   = ["aws_cloudwatch_log_group.log_group"]

}

data "archive_file" "lambda_archive" {
  type        = "zip"
  source_file = "${path.module}/../target/handler-1.0-SNAPSHOT.jar"
  output_path = "${path.module}/../target/code.zip"
}

My goal is to figure out the proper way to reference the JAR file location so that CodePipeline can locate it and successfully upload it to the Lambda function during deployment.

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

>Solution :

The JAR file would be git-ignored and built separately before running the Terraform code. The Terraform would then zip up the freshly built JAR and deploy it to Lambda. Check your target folder and JAR file, are they git-ignored? If yes, you can remove them and give it another try.

Refer to the Link.

Kindly, let me know if it works.

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading