将 AWS Lambda 与 Amazon Lex 结合使用的 Terraform

Terraform For Using AWS Lambda With Amazon Lex

我在尝试让 fulfillment_activity codehook 工作以便我可以将 Lambda 函数用于后端时遇到了一些问题。出于某种原因,我从 Terraform 收到此错误消息。

Error: error waiting for Lex Bot (helloBot) create: unexpected state 'FAILED', wanted target 'NOT_BUILT, READY, READY_BASIC_TESTING'. last error: Intent 'sample_intent' has an invalid message version defined for its fulfillment.

这是我的 Terraform 配置:

# AWS Lex Bot
resource "aws_lex_bot" "helloBot" {
  depends_on = [ aws_lex_intent.sample_intent ]
  locale                      = "en-US"
  name                        = "helloBot"
  process_behavior            = "BUILD"
  voice_id                    = "Salli"
  create_version              = true
  idle_session_ttl_in_seconds = 300
  child_directed              = false

  abort_statement {
    message {
      content      = "Abort Abort!"
      content_type = "PlainText"
    }
  }

  clarification_prompt {
    max_attempts = 2

    message {
      content      = "No Idea What You're Saying!"
      content_type = "PlainText"
    }
  }

  intent {
    intent_name    = "sampleIntentName"
    intent_version = aws_lex_intent.sample_intent.version
  }
}

resource "aws_lambda_permission" "lex_sample_intent_lambda" {
  statement_id  = "AllowExecutionFromAmazonLex"
  action        = "lambda:InvokeFunction"
  function_name = "someLambdaFunctionName"
  principal     = "lex.amazonaws.com"

  # https://docs.aws.amazon.com/lex/latest/dg/gs-cli-update-lambda.html
  source_arn = "arn:aws:lex:myRegion:accountId:intent:sampleIntentName:*"
}

# AWS Lex Intents
data "aws_lambda_function" "existing" {
  function_name = "someLambdaFunctionName"
  qualifier     = "dev"
}

resource "aws_lex_intent" "sample_intent" {
  create_version = true
  name           = "sampleIntentName"

  fulfillment_activity {
    type = "CodeHook"
    code_hook {
      message_version = "1.0"
      uri             = data.aws_lambda_function.existing.qualified_arn
    }
  }

  sample_utterances = [
    "hi",
    "hello"
  ]
}

我查看了 cli documentation,看来我们应该使用 "1.0" 作为消息版本。

看来 Terraform 配置应该是正确的。当它是一个变量时,问题与消息版本的数据类型有关。它被错误地设置为 number 而不是 string