github.com/recobe182/terraform@v0.8.5-0.20170117231232-49ab22a935b7/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 ``` 41 42 ## Lambda integration 43 44 ``` 45 # Variables 46 variable "myregion" {} 47 variable "accountId" {} 48 49 # API Gateway 50 resource "aws_api_gateway_rest_api" "api" { 51 name = "myapi" 52 } 53 54 resource "aws_api_gateway_method" "method" { 55 rest_api_id = "${aws_api_gateway_rest_api.api.id}" 56 resource_id = "${aws_api_gateway_rest_api.api.root_resource_id}" 57 http_method = "GET" 58 authorization = "NONE" 59 } 60 61 resource "aws_api_gateway_integration" "integration" { 62 rest_api_id = "${aws_api_gateway_rest_api.api.id}" 63 resource_id = "${aws_api_gateway_rest_api.api.root_resource_id}" 64 http_method = "${aws_api_gateway_method.method.http_method}" 65 integration_http_method = "POST" 66 type = "AWS" 67 uri = "arn:aws:apigateway:${var.myregion}:lambda:path/2015-03-31/functions/${aws_lambda_function.lambda.arn}/invocations" 68 } 69 70 # Lambda 71 resource "aws_lambda_permission" "apigw_lambda" { 72 statement_id = "AllowExecutionFromAPIGateway" 73 action = "lambda:InvokeFunction" 74 function_name = "${aws_lambda_function.lambda.arn}" 75 principal = "apigateway.amazonaws.com" 76 source_arn = "arn:aws:execute-api:${var.myregion}:${var.accountId}:${aws_api_gateway_rest_api.api.id}/*/${aws_api_gateway_method.method.http_method}/" 77 } 78 79 resource "aws_lambda_function" "lambda" { 80 filename = "lambda.zip" 81 function_name = "mylambda" 82 role = "${aws_iam_role.role.arn}" 83 handler = "lambda.lambda_handler" 84 runtime = "python2.7" 85 source_code_hash = "${base64sha256(file("lambda.zip"))}" 86 } 87 88 # IAM 89 resource "aws_iam_role" "role" { 90 name = "myrole" 91 assume_role_policy = <<POLICY 92 { 93 "Version": "2012-10-17", 94 "Statement": [ 95 { 96 "Action": "sts:AssumeRole", 97 "Principal": { 98 "Service": "lambda.amazonaws.com" 99 }, 100 "Effect": "Allow", 101 "Sid": "" 102 } 103 ] 104 } 105 POLICY 106 } 107 ``` 108 109 ## Argument Reference 110 111 The following arguments are supported: 112 113 * `rest_api_id` - (Required) The ID of the associated REST API. 114 * `resource_id` - (Required) The API resource ID. 115 * `http_method` - (Required) The HTTP method (`GET`, `POST`, `PUT`, `DELETE`, `HEAD`, `OPTION`, `ANY`) 116 when calling the associated resource. 117 * `integration_http_method` - (Optional) The integration HTTP method 118 (`GET`, `POST`, `PUT`, `DELETE`, `HEAD`, `OPTION`) specifying how API Gateway will interact with the back end. 119 **Required** if `type` is `AWS`, `AWS_PROXY`, `HTTP` or `HTTP_PROXY`. 120 Not all methods are compatible with all `AWS` integrations. 121 e.g. Lambda function [can only be invoked](https://github.com/awslabs/aws-apigateway-importer/issues/9#issuecomment-129651005) via `POST`. 122 * `type` - (Required) The integration input's type (HTTP, MOCK, AWS, AWS_PROXY, HTTP_PROXY) 123 * `uri` - (Optional) The input's URI (HTTP, AWS). **Required** if `type` is `HTTP` or `AWS`. 124 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. 125 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` 126 * `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/\*`. 127 * `request_templates` - (Optional) A map of the integration's request templates. 128 * `request_parameters` - (Optional) A map of request query string parameters and headers that should be passed to the backend responder. 129 For example: `request_parameters = { "integration.request.header.X-Some-Other-Header" = "method.request.header.X-Some-Header" }` 130 * `passthrough_behavior` - (Optional) The integration passthrough behavior (`WHEN_NO_MATCH`, `WHEN_NO_TEMPLATES`, `NEVER`). **Required** if `request_templates` is used. 131 * `request_parameters_in_json` - **Deprecated**, use `request_parameters` instead. 132 * `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.