Terraform-provider-aws: API gateway integration issue - Invalid Method identifier specified Error

Created on 31 Mar 2018  路  6Comments  路  Source: hashicorp/terraform-provider-aws

_This issue was originally opened by @ctippur as hashicorp/terraform#17747. It was migrated here as a result of the provider split. The original body of the issue is below._


Terraform Version

Terraform version: 0.11.4  

Terraform Configuration Files

data "template_file" "swagger_api" {
  template = "${file("${path.module}/swagger.yaml")}"
}


resource "aws_api_gateway_rest_api" "reset_restapi" {
  name        = "reset_restapi"
  description = "Rest api based on swagger doc"
  body = "${data.template_file.swagger_api.rendered}"

}

resource "aws_api_gateway_integration" "integration" {
  rest_api_id             = "${aws_api_gateway_rest_api.pwreset_restapi.id}"
  resource_id             = "${aws_api_gateway_rest_api.pwreset_restapi.root_resource_id}"
  http_method             = "PUT"
  integration_http_method = "PUT"
  type                    = "AWS_PROXY"
  uri                     = "arn:aws:apigateway:${var.myregion}:lambda:path/2015-03-31/functions/${var.reset_fn_arn}/invocations"
}

## Please note that var.reset_fn_arn is getting created and passed from another module

Debug Output

module.pw_apigw.aws_api_gateway_integration.integration: Creating...
  cache_namespace:         "" => "<computed>"
  http_method:             "" => "PUT"
2018-03-30T16:18:43.632-0700 [DEBUG] plugin.terraform-provider-aws_v1.13.0_x4: 2018/03/30 16:18:43 [DEBUG] Creating API Gateway Integration
  integration_http_method: "" => "PUT"
  passthrough_behavior:    "" => "<computed>"
  resource_id:             "" => "xjgjcjl7xh"
  rest_api_id:             "" => "0qx374uk6h"
  type:                    "" => "AWS_PROXY"
2018-03-30T16:18:43.633-0700 [DEBUG] plugin.terraform-provider-aws_v1.13.0_x4: 2018/03/30 16:18:43 [DEBUG] [aws-sdk-go] DEBUG: Request apigateway/PutIntegration Details:
2018-03-30T16:18:43.633-0700 [DEBUG] plugin.terraform-provider-aws_v1.13.0_x4: ---[ REQUEST POST-SIGN ]-----------------------------
2018-03-30T16:18:43.633-0700 [DEBUG] plugin.terraform-provider-aws_v1.13.0_x4: PUT /restapis/0qx374uk6h/resources/xjgjcjl7xh/methods/PUT/integration HTTP/1.1
2018-03-30T16:18:43.633-0700 [DEBUG] plugin.terraform-provider-aws_v1.13.0_x4: Host: apigateway.us-west-2.amazonaws.com
2018-03-30T16:18:43.633-0700 [DEBUG] plugin.terraform-provider-aws_v1.13.0_x4: User-Agent: aws-sdk-go/1.13.21 (go1.9.2; darwin; amd64) APN/1.0 HashiCorp/1.0 Terraform/0.11.4
2018-03-30T16:18:43.633-0700 [DEBUG] plugin.terraform-provider-aws_v1.13.0_x4: Content-Length: 221
2018-03-30T16:18:43.633-0700 [DEBUG] plugin.terraform-provider-aws_v1.13.0_x4: Accept: application/json
2018-03-30T16:18:43.633-0700 [DEBUG] plugin.terraform-provider-aws_v1.13.0_x4: Authorization: AWS4-HMAC-SHA256 Credential=ASIAJRKEXKLLI65QYOKA/20180330/us-west-2/apigateway/aws4_request, SignedHeaders=accept;content-length;host;x-amz-date;x-amz-security-token, Signature=7ca55f4eb1d793564298eb5237fec4c330266254582f1e11577680ba48825302
2018-03-30T16:18:43.633-0700 [DEBUG] plugin.terraform-provider-aws_v1.13.0_x4: X-Amz-Date: 20180330T231843Z
  uri:                     "" => "arn:aws:apigateway:us-west-2:lambda:path/2015-03-31/functions/arn:aws:lambda:us-west-2:008743059065:function:pwreset/invocations"
2018-03-30T16:18:43.633-0700 [DEBUG] plugin.terraform-provider-aws_v1.13.0_x4: X-Amz-Security-Token: FQoDYXdzEOD//////////wEaDPasLJVQGqs52rul6yL5AS0Pw/09MppJLacZhXIQWCKUpaLfIOIALMEbNKg6/ew7KQznC07I4uwJJxvA2HW99qQQs3Alodh/dAD3WKNf1In58vlRpFIsGtRz/EDFwXd7oW9nmnJi1lT9ksjRaZSj2Pu0L3rHxBRTMdkEqHhFQu/BYL4WV9IHlF10fiTIIXMD+BD7omDdzvyYPBlmWo3R1+TG2zMtL9JyJ4bqfFNHE5crOohrTM7DQCJCaJst6lMl8mKxoybrAl6GLmClST9V9m/aLQhXNC6atoj5264bK2NeuF6etb/mQq5u7upbabLjww3A/+W9CDJ2PJ0vcNQCBVcJ+WzTgNkpwCib8vrVBQ==
2018-03-30T16:18:43.633-0700 [DEBUG] plugin.terraform-provider-aws_v1.13.0_x4: Accept-Encoding: gzip
2018-03-30T16:18:43.633-0700 [DEBUG] plugin.terraform-provider-aws_v1.13.0_x4: 
2018-03-30T16:18:43.633-0700 [DEBUG] plugin.terraform-provider-aws_v1.13.0_x4: -----------------------------------------------------
2018-03-30T16:18:44.288-0700 [DEBUG] plugin.terraform-provider-aws_v1.13.0_x4: 2018/03/30 16:18:44 [DEBUG] [aws-sdk-go] DEBUG: Response apigateway/PutIntegration Details:
2018-03-30T16:18:44.289-0700 [DEBUG] plugin.terraform-provider-aws_v1.13.0_x4: ---[ RESPONSE ]--------------------------------------
2018-03-30T16:18:44.289-0700 [DEBUG] plugin.terraform-provider-aws_v1.13.0_x4: HTTP/2.0 404 Not Found
2018-03-30T16:18:44.289-0700 [DEBUG] plugin.terraform-provider-aws_v1.13.0_x4: Content-Length: 50
2018-03-30T16:18:44.289-0700 [DEBUG] plugin.terraform-provider-aws_v1.13.0_x4: Content-Type: application/json
2018-03-30T16:18:44.289-0700 [DEBUG] plugin.terraform-provider-aws_v1.13.0_x4: Date: Fri, 30 Mar 2018 23:18:44 GMT
2018-03-30T16:18:44.289-0700 [DEBUG] plugin.terraform-provider-aws_v1.13.0_x4: X-Amzn-Errortype: NotFoundException
2018-03-30T16:18:44.289-0700 [DEBUG] plugin.terraform-provider-aws_v1.13.0_x4: X-Amzn-Requestid: b0cc719f-3470-11e8-9f6c-9dc9e139d5ce
2018-03-30T16:18:44.289-0700 [DEBUG] plugin.terraform-provider-aws_v1.13.0_x4: 
2018-03-30T16:18:44.289-0700 [DEBUG] plugin.terraform-provider-aws_v1.13.0_x4: 
2018-03-30T16:18:44.289-0700 [DEBUG] plugin.terraform-provider-aws_v1.13.0_x4: -----------------------------------------------------
2018-03-30T16:18:44.289-0700 [DEBUG] plugin.terraform-provider-aws_v1.13.0_x4: 2018/03/30 16:18:44 [DEBUG] [aws-sdk-go] {"message":"Invalid Method identifier specified"}
2018-03-30T16:18:44.289-0700 [DEBUG] plugin.terraform-provider-aws_v1.13.0_x4: 2018/03/30 16:18:44 [DEBUG] [aws-sdk-go] DEBUG: Validate Response apigateway/PutIntegration failed, not retrying, error NotFoundException: **Invalid Method identifier specified**
2018-03-30T16:18:44.289-0700 [DEBUG] plugin.terraform-provider-aws_v1.13.0_x4:  status code: 404, request id: b0cc719f-3470-11e8-9f6c-9dc9e139d5ce

Crash Output

Expected Behavior

Resource and integrations created as specified

Actual Behavior


Got the error

* module.pw_apigw.aws_api_gateway_integration.integration: 1 error(s) occurred:

* aws_api_gateway_integration.integration: Error creating API Gateway Integration: NotFoundException: Invalid Method identifier specified
        status code: 404, 

Steps to Reproduce

  • terraform init
  • terraform apply
  • Additional Context

    References

    question servicapigateway

    Most helpful comment

    Hello there, just wanted to check if that has been fixed or if there are any knows workarounds for creating aws_api_gateway_method_response from terraform? As I'm running into that issue now and it seems like there is no way to create method and integration responses with terraform..

    All 6 comments

    I think it maybe my understanding of `path_part in

    If my path is

    /rh/region/{region}/environment/{environment}
    

    What should my path_part be?

    How should I write aws_api_gateway_method?

    request_parameters {
    "method.request.path.environment" = true
    }

    
    resource "aws_api_gateway_resource" reset_resource" {
      rest_api_id = "${aws_api_gateway_rest_api.reset_restapi.id}"
      parent_id   = "${aws_api_gateway_rest_api.reset_restapi.root_resource_id}"
      path_part   = "{environment}"
    }
    

    I believe lambdas have to have an integration method of POST per https://www.terraform.io/docs/providers/aws/r/api_gateway_integration.html

    integration_http_method - (Optional) The integration HTTP method (GET, POST, PUT, DELETE, HEAD, OPTION) specifying how API Gateway will interact with the back end. Required if type is AWS, AWS_PROXY, HTTP or HTTP_PROXY. Not all methods are compatible with all AWS integrations. e.g. Lambda function can only be invoked via POST.

    That said, I get this on my first apply with POST, and if I apply the same .tf's again, it works fine. I have a feeling that somehow the error is misleading.

    Hello there, just wanted to check if that has been fixed or if there are any knows workarounds for creating aws_api_gateway_method_response from terraform? As I'm running into that issue now and it seems like there is no way to create method and integration responses with terraform..

    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
    }
    

    Adding 5 seconds delay before the response resource creation works good for me.

    I encountered similar issue of Invalid Method identifier when creating aws_resouce aws_api_gateway_integration_response.

    Scenario:
    A POST method, LAMBDA_PROXY with response method and integration response.
    After the first apply, aws_api_gateway_integration.integration: Error creating API Gateway Integration: NotFoundException: Invalid Method identifier specified was encountered. The second apply would finish the remaining (integration and deployment) resources without issues.

    Solution:
    Add all the necessary dependencies (resource) for each resources.

    resource "aws_api_gateway_rest_api" "apigw" {
      name = apigw
    }
    
    resource "aws_api_gateway_resource" "resource" {
      rest_api_id = aws_api_gateway_rest_api.apigw.id
      parent_id   = aws_api_gateway_rest_api.apigw.root_resource_id
      path_part   = "resource"
    
      depends_on = [ aws_api_gateway_rest_api.apigw ]
    }
    
    
    
    md5-c0fae95fd9658b95ac7d0c3d0749aee6
    
    
    
    resource "aws_api_gateway_method" "post_method" {
      rest_api_id          = aws_api_gateway_rest_api.apigw.id
      resource_id          = aws_api_gateway_resource.resource.id
      http_method          = "POST"
      authorization        = "NONE"
    
      depends_on = [
        aws_api_gateway_resource.resource
      ]
    }
    
    
    
    md5-c0fae95fd9658b95ac7d0c3d0749aee6
    
    
    
    resource "aws_api_gateway_method_response" "post_method_response" {
      rest_api_id   = aws_api_gateway_rest_api.apigw.id
      resource_id   = aws_api_gateway_resource.resource.id
      http_method   = aws_api_gateway_method.post_method.http_method
      status_code   = "200"
    
      depends_on = [
        aws_api_gateway_method.post_method
      ]
    }
    
    
    
    md5-c0fae95fd9658b95ac7d0c3d0749aee6
    
    
    
    resource "aws_api_gateway_integration" "lambda_integration" {
      rest_api_id             = aws_api_gateway_rest_api.apigw.id
      resource_id             = aws_api_gateway_resource.resource.id
      http_method             = aws_api_gateway_method.post_method.http_method
      integration_http_method = "POST"
      type                    = "AWS_PROXY"
      uri                     = aws_lambda_function.my_lambda_function.invoke_arn
    
      depends_on = [
        aws_lambda_function.my_lambda_function,
        aws_api_gateway_method.post_method
      ]
    }
    
    
    
    md5-561ca605f719ea75e2e65d062f20ce32
    
    
    
    resource "aws_api_gateway_integration_response" "post_integration_response" {
      rest_api_id = aws_api_gateway_rest_api.apigw.id
      resource_id = aws_api_gateway_resource.resource.id
      http_method = aws_api_gateway_method.post_method.http_method
      status_code = aws_api_gateway_method_response.post_method_response.status_code
    
      depends_on = [
        aws_lambda_function.my_lambda_function,
        aws_api_gateway_integration.lambda_integration,
        aws_api_gateway_method_response.post_method_response
      ]
    }
    
    
    
    md5-37774c1b48795447db044e1d13abd4fb
    
    
    
    resource "aws_api_gateway_deployment" "deploy_apigw" {
      rest_api_id       = aws_api_gateway_rest_api.apigw.id
      stage_name        = "stage"
      stage_description = "deployment stage"
      description       = "deployment"
    
      depends_on = [
        aws_api_gateway_rest_api.apigw,
        aws_api_gateway_resource.resource,
        aws_api_gateway_method.post_method,
        aws_api_gateway_method_response.post_method_response,
        aws_api_gateway_integration.lambda_integration,
        aws_api_gateway_integration_response.post_integration_response,
      ]
    }
    
    Was this page helpful?
    0 / 5 - 0 ratings