Skip to content
Switch branches/tags

Latest commit


Git stats


Failed to load latest commit information.
Latest commit message
Commit time

Terraform Package Lambda Build status

This module runs npm ci in an isolated directory and zip's the result in preparation for upload to AWS Lambda. The resulting zip file is produced in a deterministic way that will be consistent across multiple Nix platforms. The module includes its dependencies so it can be executed within Terraform Cloud.


If executing this in an environment outside of Terraform Cloud or Ubuntu 18.04, install this module's dependencies:

brew tap orf/brew
brew install deterministic-zip jq coreutils

Additionally, you will need npm and rsync. It's assumed you have these already on your system.


Assuming a file structure like:

project-dir/               # → Root folder for the project
├──                # → Terraform configuration
├── files/lambda/          # → The directory containing the lambda function
├── files/lambda/index.js
└── files/lambda/package.json

And this configuration:

module "lambda_zip" {
  source = ""

  source_dir  = "${path.module}/files/lambda"
  output_path = "${path.module}/files/"

Then a packaged zip would be produced at project-dir/files/

Can be used in conjunction with a lambda function resource like so:

module "lambda_zip" {
  source = ""

  source_dir  = "${path.module}/files/lambda"
  output_path = "${path.module}/files/"

resource "aws_lambda_function" "mod" {
  filename = "${module.lambda_zip.zip_file}"

  source_code_hash = "${module.lambda_zip.output_base64sha256}"

  function_name = "some-lambda-function"
  description   = "Lambda code for monitoring URL's and deregistering instances when they fail a healthcheck."

  # ... additional config