Skip to content
This repository has been archived by the owner on Feb 5, 2024. It is now read-only.

Bypass need for SLS #34

Closed
andyrichardson opened this issue Nov 29, 2019 · 1 comment
Closed

Bypass need for SLS #34

andyrichardson opened this issue Nov 29, 2019 · 1 comment

Comments

@andyrichardson
Copy link

andyrichardson commented Nov 29, 2019

I've been looking at some provider documentation and it looks like we could possibly cut SLS out of the equation completely.

The below (primitive) example enables archiving of a function (one file for now) and deploying to lambda.

Every time plan/apply is run, the archive file is recreated and lambda will check if the new archive checksum matches that of the deployed archive. There is also a similar funciton for layers.

provider "archive" {}

locals {
  sourcefile = "${path.module}/../${var.function["filepath"]}"
  archive = "${path.module}/../dist/${replace("${var.function["filepath"]}", "/.js/", ".zip")}"
}


data "archive_file" "init" {
  type        = "zip"
  source_file = "${local.sourcefile}"
  output_path = "${local.archive}"
}

resource "aws_lambda_function" "test_lambda" {
  filename      = "${data.archive_file.init.output_path}"
  function_name = "${var.function["name"]}"
  handler       = "${var.function["handler"]}"

  # The filebase64sha256() function is available in Terraform 0.11.12 and later
  # For Terraform 0.11.11 and earlier, use the base64sha256() function and the file() function:
  # source_code_hash = "${base64sha256(file("lambda_function_payload.zip"))}"
  source_code_hash = "${filebase64sha256("${data.archive_file.init.output_path}")}"
  runtime = "${var.function["runtime"]}"
}

variable "function" {
  type = "map"
  default = {
    name = "base_fn"
    filepath = "src/server/base.js"
    runtime = "nodejs8.10"
    handler = "exports.handler"
  }
}

There's probably a bunch of scenarios still to consider:

  • Archival of multiple files
  • Permission issues (can a dev run this along with the existing terraform config?)
@andyrichardson
Copy link
Author

Closing as this is outside the scope of this repo

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant