创建 API 网关集成响应时出错:NotFoundException:指定的集成标识符无效
Error creating API Gateway Integration Response: NotFoundException: Invalid Integration identifier specified
Objective
问题的解决方案或解决方法。
问题
如果预先单独创建 Firehose,则下面的 Terraform API 网关与 Firehose 的集成工作。
resource "aws_api_gateway_integration" "click_put" {
rest_api_id = data.aws_api_gateway_rest_api.mysfit.id
resource_id = aws_api_gateway_resource.click.id
type = "AWS"
uri = "arn:aws:apigateway:${var.REGION}:firehose:action/PutRecord"
credentials = aws_iam_role.api_click.arn
http_method = aws_api_gateway_method.click_put.http_method
integration_http_method = "POST"
request_parameters = {
"integration.request.header.Content-Type" = "'application/x-amz-json-1.1'"
}
passthrough_behavior = "NEVER"
request_templates = {
"application/json" = <<EOF
{
"DeliveryStreamName": "${local.firehose_name}",
"Record": {
"Data": "$util.base64Encode($input.json('$'))"
}
}
EOF
}
}
...
resource "aws_api_gateway_integration_response" "click_put" {
rest_api_id = data.aws_api_gateway_rest_api.mysfit.id
resource_id = aws_api_gateway_resource.click.id
http_method = aws_api_gateway_method.click_put.http_method
status_code = aws_api_gateway_method_response.click_put.status_code
response_parameters = {
"method.response.header.Access-Control-Allow-Origin" = "'*'"
}
}
但是,如果它们是在同一个根模块中创建的,则会导致错误。
Error creating API Gateway Integration Response: NotFoundException: Invalid Integration identifier specified
on api_click.tf line 185, in resource "aws_api_gateway_integration_response" "click_put":
185: resource "aws_api_gateway_integration_response" "click_put" {
Workaround/Solution
从导致 "NotFoundException: Invalid Integration identifier specified".
的资源中放置对 aws_api_gateway_integration 的依赖
resource "aws_api_gateway_integration_response" "click_put" {
rest_api_id = data.aws_api_gateway_rest_api.mysfit.id
resource_id = aws_api_gateway_resource.click.id
http_method = aws_api_gateway_method.click_put.http_method
status_code = aws_api_gateway_method_response.click_put.status_code
response_parameters = {
"method.response.header.Access-Control-Allow-Origin" = "'*'"
}
depends_on = [
aws_api_gateway_integration.click_put
]
}
参考资料
有迹象表明 depends_on aws_api_gateway_integration 或稍候即可。
可能等待 aws_api_gateway_integration 资源完全完成是推荐的做法。
aws_api_gateway_integration_response
Note: Depends on having aws_api_gateway_integration inside your rest api. To ensure this you might need to add an explicit depends_on for clean runs.
API gateway integration issue - Invalid Method identifier specified Error #4001
I'm using the following workaround to solve a similar issue. I'm getting the Invalid Method identifier error on the first run when all the resources are created during the same apply. A proxy API for Lambda is created:
resource "aws_api_gateway_resource" "proxy" {
rest_api_id = aws_api_gateway_rest_api.rest-api.id
parent_id = aws_api_gateway_rest_api.rest-api.root_resource_id
path_part = "{proxy+}"
}
resource "null_resource" "method-delay" {
provisioner "local-exec" {
command = "sleep 5"
}
triggers = {
response = aws_api_gateway_resource.proxy.id
}
}
resource "aws_api_gateway_method_response" "response" {
depends_on = [null_resource.method-delay]
http_method = "ANY"
resource_id = aws_api_gateway_resource.proxy.id
rest_api_id = aws_api_gateway_rest_api.rest-api.id
}
你可以只添加 depends_on
。应该是这样的:
resource "aws_api_gateway_integration" "create-oauth-lambda" {
rest_api_id = aws_api_gateway_rest_api.create-oauth-token-api-gw.id
resource_id = aws_api_gateway_resource.auth-token-resource.id
http_method = aws_api_gateway_method.method.http_method
integration_http_method = "POST"
type = "AWS_PROXY"
uri = "some URI"
}
resource "aws_api_gateway_method_response" "response-200" {
depends_on = [aws_api_gateway_integration.create-oauth-lambda]
rest_api_id = aws_api_gateway_rest_api.create-oauth-token-api-gw.id
resource_id = aws_api_gateway_resource.auth-token-resource.id
http_method = aws_api_gateway_method.method.http_method
status_code = "200"
response_models = {
"application/json" = "Empty"
}
}
Objective
问题的解决方案或解决方法。
问题
如果预先单独创建 Firehose,则下面的 Terraform API 网关与 Firehose 的集成工作。
resource "aws_api_gateway_integration" "click_put" {
rest_api_id = data.aws_api_gateway_rest_api.mysfit.id
resource_id = aws_api_gateway_resource.click.id
type = "AWS"
uri = "arn:aws:apigateway:${var.REGION}:firehose:action/PutRecord"
credentials = aws_iam_role.api_click.arn
http_method = aws_api_gateway_method.click_put.http_method
integration_http_method = "POST"
request_parameters = {
"integration.request.header.Content-Type" = "'application/x-amz-json-1.1'"
}
passthrough_behavior = "NEVER"
request_templates = {
"application/json" = <<EOF
{
"DeliveryStreamName": "${local.firehose_name}",
"Record": {
"Data": "$util.base64Encode($input.json('$'))"
}
}
EOF
}
}
...
resource "aws_api_gateway_integration_response" "click_put" {
rest_api_id = data.aws_api_gateway_rest_api.mysfit.id
resource_id = aws_api_gateway_resource.click.id
http_method = aws_api_gateway_method.click_put.http_method
status_code = aws_api_gateway_method_response.click_put.status_code
response_parameters = {
"method.response.header.Access-Control-Allow-Origin" = "'*'"
}
}
但是,如果它们是在同一个根模块中创建的,则会导致错误。
Error creating API Gateway Integration Response: NotFoundException: Invalid Integration identifier specified
on api_click.tf line 185, in resource "aws_api_gateway_integration_response" "click_put":
185: resource "aws_api_gateway_integration_response" "click_put" {
Workaround/Solution
从导致 "NotFoundException: Invalid Integration identifier specified".
的资源中放置对 aws_api_gateway_integration 的依赖resource "aws_api_gateway_integration_response" "click_put" {
rest_api_id = data.aws_api_gateway_rest_api.mysfit.id
resource_id = aws_api_gateway_resource.click.id
http_method = aws_api_gateway_method.click_put.http_method
status_code = aws_api_gateway_method_response.click_put.status_code
response_parameters = {
"method.response.header.Access-Control-Allow-Origin" = "'*'"
}
depends_on = [
aws_api_gateway_integration.click_put
]
}
参考资料
有迹象表明 depends_on aws_api_gateway_integration 或稍候即可。
可能等待 aws_api_gateway_integration 资源完全完成是推荐的做法。
aws_api_gateway_integration_response
Note: Depends on having aws_api_gateway_integration inside your rest api. To ensure this you might need to add an explicit depends_on for clean runs.
API gateway integration issue - Invalid Method identifier specified Error #4001
I'm using the following workaround to solve a similar issue. I'm getting the Invalid Method identifier error on the first run when all the resources are created during the same apply. A proxy API for Lambda is created:
resource "aws_api_gateway_resource" "proxy" {
rest_api_id = aws_api_gateway_rest_api.rest-api.id
parent_id = aws_api_gateway_rest_api.rest-api.root_resource_id
path_part = "{proxy+}"
}
resource "null_resource" "method-delay" {
provisioner "local-exec" {
command = "sleep 5"
}
triggers = {
response = aws_api_gateway_resource.proxy.id
}
}
resource "aws_api_gateway_method_response" "response" {
depends_on = [null_resource.method-delay]
http_method = "ANY"
resource_id = aws_api_gateway_resource.proxy.id
rest_api_id = aws_api_gateway_rest_api.rest-api.id
}
你可以只添加 depends_on
。应该是这样的:
resource "aws_api_gateway_integration" "create-oauth-lambda" {
rest_api_id = aws_api_gateway_rest_api.create-oauth-token-api-gw.id
resource_id = aws_api_gateway_resource.auth-token-resource.id
http_method = aws_api_gateway_method.method.http_method
integration_http_method = "POST"
type = "AWS_PROXY"
uri = "some URI"
}
resource "aws_api_gateway_method_response" "response-200" {
depends_on = [aws_api_gateway_integration.create-oauth-lambda]
rest_api_id = aws_api_gateway_rest_api.create-oauth-token-api-gw.id
resource_id = aws_api_gateway_resource.auth-token-resource.id
http_method = aws_api_gateway_method.method.http_method
status_code = "200"
response_models = {
"application/json" = "Empty"
}
}