Skip to content

Commit 3228bd2

Browse files
Ninirstack72
authored andcommitted
provider/aws: Improved the API Gateway Integration documentation (hashicorp#10772)
1 parent 923a110 commit 3228bd2

1 file changed

Lines changed: 75 additions & 6 deletions

File tree

website/source/docs/providers/aws/r/api_gateway_integration.html.markdown

Lines changed: 75 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -39,22 +39,91 @@ resource "aws_api_gateway_integration" "MyDemoIntegration" {
3939
}
4040
```
4141

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+
42109
## Argument Reference
43110

44111
The following arguments are supported:
45112

46-
* `rest_api_id` - (Required) The ID of the associated REST API
47-
* `resource_id` - (Required) The API resource ID
113+
* `rest_api_id` - (Required) The ID of the associated REST API.
114+
* `resource_id` - (Required) The API resource ID.
48115
* `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`.
49122
* `type` - (Required) The integration input's type (HTTP, MOCK, AWS, AWS_PROXY, HTTP_PROXY)
50123
* `uri` - (Optional) The input's URI (HTTP, AWS). **Required** if `type` is `HTTP` or `AWS`.
51124
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.
52125
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`
53126
* `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/\*`.
54-
* `integration_http_method` - (Optional) The integration HTTP method
55-
(`GET`, `POST`, `PUT`, `DELETE`, `HEAD`, `OPTION`). **Required** if `type` is `AWS` or `HTTP`.
56-
Not all methods are compatible with all `AWS` integrations.
57-
e.g. Lambda function [can only be invoked](https://github.com/awslabs/aws-apigateway-importer/issues/9#issuecomment-129651005) via `POST`.
58127
* `request_templates` - (Optional) A map of the integration's request templates.
59128
* `request_parameters` - (Optional) A map of request query string parameters and headers that should be passed to the backend responder.
60129
For example: `request_parameters = { "integration.request.header.X-Some-Other-Header" = "method.request.header.X-Some-Header" }`

0 commit comments

Comments
 (0)