1

Got a lambda handler written in Typescript. So I have a compile script:

    "precompile": "rm -rf dist",
    "compile": "npx tsc --moduleResolution node --outDir dist --sourceMap false",

Works fine. Then I thought I'd zip up the dist folder and the node_modules before uploading (with a prune beforehand):

# zip the handler code before sending it
data "archive_file" "lambda_zip_file" {
  type = "zip"
  source_dir = "${path.module}/../dist"
  source_dir = "${path.module}/../node_modules"
  output_path = "${path.module}/../${var.tempfolder}/${local.prefix}.zip"
}

archive_file docs

OK well source_dir doesn't allow two sources. Or an array of sources. So my alternative is to cp the node_modules folder to the dist folder before I call Terraform. Which isn't a big deal, just wondering if there's a better way that I'm not seeing. Cleaner if I don't have a temp folder to in my file tree.

Terraform 1.0.x

jcollum
  • 43,623
  • 55
  • 191
  • 321

1 Answers1

2

I wanted to comment, but sadly cannot.
So I don't think there isn't really a better option rather than copying all the needed stuff into one directory and the archiving. You could point specific source files (https://stackoverflow.com/a/56928455/19635908), but I don't think that's what you want as you want the whole node_modules and dist.
What I could recommend though is trying out a function packager for node which can do all the building and zipping for you.
https://www.npmjs.com/package/funpack
Let me know what you think

eric
  • 21
  • 2