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