无法使用Terraform将Lambda函数与api网关集成

时间:2020-06-25 11:32:37

标签: terraform integration aws-api-gateway api-gateway

我正在处理terraform api网关集成挑战,我不了解会发生什么。我按照教程创建lambda函数并将其正确上传到S3。 接下来,我创建了此文件以创建API网关并集成lambda函数

这是我的代码

resource "aws_api_gateway_rest_api" "example" {
  name        = "ServerlessExample"
  description = "Terraform Serverless Application Example"
}

resource "aws_api_gateway_resource" "MyDemoResource" {
  rest_api_id = "${aws_api_gateway_rest_api.example.id}"
  parent_id   = "${aws_api_gateway_rest_api.example.root_resource_id}"
  path_part   = "item"
}

resource "aws_api_gateway_method" "MyDemoMethod" {
  rest_api_id   = "${aws_api_gateway_rest_api.example.id}"
  resource_id   = "${aws_api_gateway_resource.MyDemoResource.id}"
  http_method   = "GET"
  authorization = "NONE"
}

 resource "aws_api_gateway_integration" "integration" {
  rest_api_id             = "${aws_api_gateway_rest_api.example.id}"
  resource_id             = "${aws_api_gateway_resource.MyDemoResource.id}"
  http_method             = "${aws_api_gateway_method.MyDemoMethod.http_method}"
  integration_http_method = "POST"
  type                    = "AWS_PROXY"
  uri                     = "${aws_lambda_function.example.invoke_arn}$"
}

resource "aws_api_gateway_deployment" "example" {
   depends_on = [
     aws_api_gateway_integration.lambda_root
   ]

   rest_api_id = aws_api_gateway_rest_api.example.id
   stage_name  = "dev"
 }


output "base_url" {
  value = aws_api_gateway_deployment.example.invoke_url
}

在进行Terraform应用时,出现此错误

Error: Reference to undeclared resource

  on api_gateway.tf line 30, in resource "aws_api_gateway_deployment" "example":
  30:      aws_api_gateway_integration.lambda_root

A managed resource "aws_api_gateway_integration" "lambda_root" has not been
declared in the root module.

0 个答案:

没有答案