9

में एक aws_api_gateway_integration के लिए एक अनुरोध टेम्पलेट निर्दिष्ट Terraform documentation for AWS_API_GATEWAY_INTEGRATION में, निम्न पैरामीटर समर्थित हैं:terraform

  • rest_api_id
  • RESOURCE_ID
  • http_method
  • प्रकार
  • uri
  • integration_http_method

वे इस उदाहरण दे:

resource "aws_api_gateway_integration" "MyDemoIntegration" { 
    rest_api_id = "${aws_api_gateway_rest_api.MyDemoAPI.id}" 
    resource_id = "${aws_api_gateway_resource.MyDemoResource.id}" 
    http_method = "${aws_api_gateway_method.MyDemoMethod.http_method}" 
    type = "MOCK" 
} 

लेकिन मैं के रूप में आप यूआई के साथ कर सकते हैं एक मानचित्रण टेम्पलेट (और साथ ही एक लैम्ब्डा एकीकरण) निर्दिष्ट करने के लिए चाहते हैं,:

enter image description here

हालांकि मुझे टेराफॉर्म के साथ ऐसा करने का कोई तरीका नहीं दिखता है। क्या संभव है?

नोट: क्या मैं वर्तमान में कर रहा हूँ apply विन्यास के बाकी ing है (लैम्ब्डा, एस 3, iam आदि ...), और फिर मानचित्रण टेम्पलेट मैन्युअल रूप से जोड़ने के बाद (और साथ ही लैम्ब्डा के एकीकरण प्रकार) ।

लेकिन फिर हर बार जब मैं terraform apply कुछ अन्य कॉन्फ़िगरेशन (उदाहरण: एस 3) लागू करने के लिए, टेराफॉर्म मैपिंग टेम्पलेट और एकीकरण प्रकार को वापस ले देता है।

"को वापस लाने में" योजना इस तरह दिखता है:

(आप पैरामीटर uri, type, integration_http_method और request_templates उपयोग करने के लिए):

~ aws_api_gateway_integration.post_hit_integration 
    request_templates.#:    "1" => "0" 
    request_templates.application/json: "{\n \"body\" : $input.json('$'),\n \"headers\": {\n #foreach($param in $input.params().header.keySet())\n \"$param\": \"$util.escapeJavaScript($input.params().header.get($param))\" #if($foreach.hasNext),#end\n \n #end \n },\n \"stage\" : \"$context.stage\"\n}" => "" 
    uri:        "arn:aws:apigateway:eu-west-1:lambda:path/2015-03-31/functions/arn:aws:lambda:eu-west-1:000000000000:function:create_hit/invocations" => "" 

उत्तर

11

पर this issue आधार पर, यहाँ एक config कि काम करता है

# API 
resource "aws_api_gateway_rest_api" "my_api" { 
    name = "my_api" 
    description = "My Api for adding pets" 
} 

# Resource 
resource "aws_api_gateway_resource" "pets_resource" { 
    rest_api_id = "${aws_api_gateway_rest_api.my_api.id}" 
    parent_id = "${aws_api_gateway_rest_api.my_api.root_resource_id}" 
    path_part = "pets" 
} 

# Method 
resource "aws_api_gateway_method" "post_pet_method" { 
    rest_api_id = "${aws_api_gateway_rest_api.my_api.id}" 
    resource_id = "${aws_api_gateway_resource.pets_resource.id}" 
    http_method = "POST" 
    authorization = "NONE" 
} 

# Integration 
resource "aws_api_gateway_integration" "post_pet_integration" { 
    rest_api_id = "${aws_api_gateway_rest_api.my_api.id}" 
    resource_id = "${aws_api_gateway_resource.pets_resource.id}" 
    http_method = "${aws_api_gateway_method.post_pet_method.http_method}" 
    uri = "arn:aws:apigateway:${var.region}:lambda:path/2015-03-31/functions/${aws_lambda_function.create_pet.arn}/invocations" 
    type = "AWS"       # Documentation not clear 
    integration_http_method = "POST"  # Not documented 
    request_templates = {     # Not documented 
    "application/json" = "${file("api_gateway_body_mapping.template")}" 
    } 
} 

और api_gate की सामग्री way_body_mapping.template:

{ 
    "body" : $input.json('$'), 
    "headers": { 
    #foreach($param in $input.params().header.keySet()) 
    "$param": "$util.escapeJavaScript($input.params().header.get($param))" #if($foreach.hasNext),#end 

    #end 
    }, 
    "stage" : "$context.stage" 
} 
+0

मैं इस के लिए हर जगह तलाश रहे हैं, आपको बहुत बहुत धन्यवाद। मैं पूरी तरह से शीर्षलेखों की गणना करना शुरू कर रहा था। – jstlaurent

1

आप अंत बिंदु के रूप में एक लैम्ब्डा समारोह का उपयोग कर रहे हैं, तो एकीकरण प्रकार "एडब्ल्यूएस" होगा।

यहां the AWS documentation है जो लैम्ब्डा एकीकरण बनाने की व्याख्या करता है।

यहां a GitHub post है जो दिखाता है कि टेराफॉर्म का उपयोग करके यह कैसे किया जा सकता है।

आशा है कि मदद करता है! आपको कोई भी प्रश्न हैं, तो हमें बताएं।

1

आप बल्कि एक अलग टेम्पलेट में से आप कर सकते हैं इनलाइन यह करना चाहते हैं:

request_templates = {     
    "application/json" = <<REQUEST_TEMPLATE 
    { 
    "body" : $input.json('$'), 
    "headers": { 
    #foreach($param in $input.params().header.keySet()) 
    "$param": "$util.escapeJavaScript($input.params().header.get($param))" #if($foreach.hasNext),#end 

    #end 
    }, 
    "stage" : "$context.stage" 
    } 
    REQUEST_TEMPLATE 
} 
संबंधित मुद्दे