github.com/greysond/terraform@v0.8.5-0.20170124173113-439b5507bbe9/website/source/docs/providers/aws/r/api_gateway_integration.html.markdown (about) 1 --- 2 layout: "aws" 3 page_title: "AWS: aws_api_gateway_integration" 4 sidebar_current: "docs-aws-resource-api-gateway-integration" 5 description: |- 6 Provides an HTTP Method Integration for an API Gateway Resource. 7 --- 8 9 # aws\_api\_gateway\_integration 10 11 Provides an HTTP Method Integration for an API Gateway Resource. 12 13 ## Example Usage 14 15 ``` 16 resource "aws_api_gateway_rest_api" "MyDemoAPI" { 17 name = "MyDemoAPI" 18 description = "This is my API for demonstration purposes" 19 } 20 21 resource "aws_api_gateway_resource" "MyDemoResource" { 22 rest_api_id = "${aws_api_gateway_rest_api.MyDemoAPI.id}" 23 parent_id = "${aws_api_gateway_rest_api.MyDemoAPI.root_resource_id}" 24 path_part = "mydemoresource" 25 } 26 27 resource "aws_api_gateway_method" "MyDemoMethod" { 28 rest_api_id = "${aws_api_gateway_rest_api.MyDemoAPI.id}" 29 resource_id = "${aws_api_gateway_resource.MyDemoResource.id}" 30 http_method = "GET" 31 authorization = "NONE" 32 } 33 34 resource "aws_api_gateway_integration" "MyDemoIntegration" { 35 rest_api_id = "${aws_api_gateway_rest_api.MyDemoAPI.id}" 36 resource_id = "${aws_api_gateway_resource.MyDemoResource.id}" 37 http_method = "${aws_api_gateway_method.MyDemoMethod.http_method}" 38 type = "MOCK" 39 40 # Transforms the incoming XML request to JSON 41 request_templates { 42 "application/xml" = <<EOF 43 { 44 "body" : $input.json('$') 45 } 46 EOF 47 } 48 } 49 ``` 50 51 ## Lambda integration 52 53 ``` 54 # Variables 55 variable "myregion" {} 56 variable "accountId" {} 57 58 # API Gateway 59 resource "aws_api_gateway_rest_api" "api" { 60 name = "myapi" 61 } 62 63 resource "aws_api_gateway_method" "method" { 64 rest_api_id = "${aws_api_gateway_rest_api.api.id}" 65 resource_id = "${aws_api_gateway_rest_api.api.root_resource_id}" 66 http_method = "GET" 67 authorization = "NONE" 68 } 69 70 resource "aws_api_gateway_integration" "integration" { 71 rest_api_id = "${aws_api_gateway_rest_api.api.id}" 72 resource_id = "${aws_api_gateway_rest_api.api.root_resource_id}" 73 http_method = "${aws_api_gateway_method.method.http_method}" 74 integration_http_method = "POST" 75 type = "AWS" 76 uri = "arn:aws:apigateway:${var.myregion}:lambda:path/2015-03-31/functions/${aws_lambda_function.lambda.arn}/invocations" 77 } 78 79 # Lambda 80 resource "aws_lambda_permission" "apigw_lambda" { 81 statement_id = "AllowExecutionFromAPIGateway" 82 action = "lambda:InvokeFunction" 83 function_name = "${aws_lambda_function.lambda.arn}" 84 principal = "apigateway.amazonaws.com" 85 source_arn = "arn:aws:execute-api:${var.myregion}:${var.accountId}:${aws_api_gateway_rest_api.api.id}/*/${aws_api_gateway_method.method.http_method}/" 86 } 87 88 resource "aws_lambda_function" "lambda" { 89 filename = "lambda.zip" 90 function_name = "mylambda" 91 role = "${aws_iam_role.role.arn}" 92 handler = "lambda.lambda_handler" 93 runtime = "python2.7" 94 source_code_hash = "${base64sha256(file("lambda.zip"))}" 95 } 96 97 # IAM 98 resource "aws_iam_role" "role" { 99 name = "myrole" 100 assume_role_policy = <<POLICY 101 { 102 "Version": "2012-10-17", 103 "Statement": [ 104 { 105 "Action": "sts:AssumeRole", 106 "Principal": { 107 "Service": "lambda.amazonaws.com" 108 }, 109 "Effect": "Allow", 110 "Sid": "" 111 } 112 ] 113 } 114 POLICY 115 } 116 ``` 117 118 ## Argument Reference 119 120 The following arguments are supported: 121 122 * `rest_api_id` - (Required) The ID of the associated REST API. 123 * `resource_id` - (Required) The API resource ID. 124 * `http_method` - (Required) The HTTP method (`GET`, `POST`, `PUT`, `DELETE`, `HEAD`, `OPTION`, `ANY`) 125 when calling the associated resource. 126 * `integration_http_method` - (Optional) The integration HTTP method 127 (`GET`, `POST`, `PUT`, `DELETE`, `HEAD`, `OPTION`) specifying how API Gateway will interact with the back end. 128 **Required** if `type` is `AWS`, `AWS_PROXY`, `HTTP` or `HTTP_PROXY`. 129 Not all methods are compatible with all `AWS` integrations. 130 e.g. Lambda function [can only be invoked](https://github.com/awslabs/aws-apigateway-importer/issues/9#issuecomment-129651005) via `POST`. 131 * `type` - (Required) The integration input's type (HTTP, MOCK, AWS, AWS_PROXY, HTTP_PROXY) 132 * `uri` - (Optional) The input's URI (HTTP, AWS). **Required** if `type` is `HTTP` or `AWS`. 133 For HTTP integrations, the URI must be a fully formed, encoded HTTP(S) URL according to the RFC-3986 specification . For AWS integrations, the URI should be of the form `arn:aws:apigateway:{region}:{subdomain.service|service}:{path|action}/{service_api}`. `region`, `subdomain` and `service` are used to determine the right endpoint. 134 e.g. `arn:aws:apigateway:eu-west-1:lambda:path/2015-03-31/functions/arn:aws:lambda:eu-west-1:012345678901:function:my-func/invocations` 135 * `credentials` - (Optional) The credentials required for the integration. For `AWS` integrations, 2 options are available. To specify an IAM Role for Amazon API Gateway to assume, use the role's ARN. To require that the caller's identity be passed through from the request, specify the string `arn:aws:iam::\*:user/\*`. 136 * `request_templates` - (Optional) A map of the integration's request templates. 137 * `request_parameters` - (Optional) A map of request query string parameters and headers that should be passed to the backend responder. 138 For example: `request_parameters = { "integration.request.header.X-Some-Other-Header" = "method.request.header.X-Some-Header" }` 139 * `passthrough_behavior` - (Optional) The integration passthrough behavior (`WHEN_NO_MATCH`, `WHEN_NO_TEMPLATES`, `NEVER`). **Required** if `request_templates` is used. 140 * `request_parameters_in_json` - **Deprecated**, use `request_parameters` instead. 141 * `content_handling` - (Optional) Specifies how to handle request payload content type conversions. Supported values are `CONVERT_TO_BINARY` and `CONVERT_TO_TEXT`. If this property is not defined, the request payload will be passed through from the method request to integration request without modification, provided that the passthroughBehaviors is configured to support payload pass-through.