簡體   English   中英

帶有 terraform 的 AWS Lambda 函數

[英]AWS Lambda function with terraform

在應用我的 terraform 計划時遇到一些問題,無法確定其中的問題。 我嘗試了我能想到的一切。 這是我的 lambda.tf 文件:

data "archive_file" "projectLeo_listunsubscribe_lambda_code" {
  type        = "zip"
  source_dir  = "${path.module}/../src/ProjectLeo.ListUnsubscribe"
  output_path = "${path.module}/../src/code-packaged/list-unsubscribe.zip"
}

resource "aws_lambda_function" "projectLeot_list_unsubscribe_lambda" {
  filename                       = "${data.archive_file.projectLeo_listunsubscribe_lambda_code.output_path}"
  function_name                  = "projectLeo-listunsubscribe-lambda"
  role                           = "${aws_iam_role.projectLeo_list_hygiene_role.arn}"
  handler                        = "${var.lambda_list_unsubscribe_function_handler}"
  runtime                        = "dotnetcore2.1"
  memory_size                    = "256"
  timeout                        = 120
  publish                        = true
  reserved_concurrent_executions = 1

  environment {
    variables = {
      optout-topic-arn = "${data.aws_sns_topic.projectLeo_optout_topic.arn}"
    }
  }
}

data "aws_sns_topic" "projectLeo_optout_topic" {
  name = "${var.sns_optout_topic_name}"
}

生成的計划看起來一切正常,但在應用完成時會生成此錯誤:

Error: Error creating Lambda function: ValidationException:
        status code: 400, request id: c16dc369-bccd-418d-a2b5-2d0383c66064

  on ..\list-unsubscribe\infrastructure\lambda.tf line 9, in resource "aws_lambda_function" "projectLeo_list_unsubscribe_lambda":
   9: resource "aws_lambda_function" "projectLeo_list_unsubscribe_lambda" {

這是一個相當輕量級的日志,我嘗試逐段更新代碼,但結果總是相同。

任何人都可以幫我查明我的代碼可能有什么問題嗎? 謝謝!

最后設法確定問題:AWS lambda 函數中的環境變量不接受連字符 (-)。 我用下划線代替它,它通過了。

optout-topic-arn 變成 optout_topic_arn

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM