Terraform not uploading Lambda code zip file to AWS

青春壹個敷衍的年華 提交于 2020-08-27 07:11:09

问题


Right now I have the following in my main.tf:

resource "aws_lambda_function" "terraform_lambda" {
  filename = "tf_lambda.zip"
  function_name = "tf_lambda"
  role = "lambda_basic_execution"
  handler = "tf_lambda.lambda_handler"
  source_code_hash = "${base64sha256(file("tf_lambda.zip"))}"
  runtime = "python3.6"
}

My directory structure is like so:

.
|-- main.tf
|-- tf_lambda.zip
|-- tf_lambda
    └── tf_lambda.py

When I run terraform apply and then, in the console, go to the lambda created the code section is empty and it invites me to upload a zip file. How do I make sure the code actually gets uploaded?


回答1:


You may also try this using archive_file, https://www.terraform.io/docs/providers/archive/d/archive_file.html So that when you run "terraform apply" the file will be re-zipped and uploaded.

data "archive_file" "zipit" {
  type        = "zip"
  source_file = "tf_lambda/tf_lambda.py"
  output_path = "tf_lambda.zip"
}


resource "aws_lambda_function" "terraform_lambda" {
  function_name = "tf_lambda"
  role = "lambda_basic_execution"
  handler = "tf_lambda.lambda_handler"
  filename = "tf_lambda.zip"
  source_code_hash = "${data.archive_file.zipit.output_base64sha256}"
  runtime = "python3.6"
}


来源:https://stackoverflow.com/questions/50357651/terraform-not-uploading-lambda-code-zip-file-to-aws

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!