diff --git a/website/source/docs/providers/aws/r/api_gateway_integration.html.markdown b/website/source/docs/providers/aws/r/api_gateway_integration.html.markdown index 34f9d74a8..d2d5ac38f 100644 --- a/website/source/docs/providers/aws/r/api_gateway_integration.html.markdown +++ b/website/source/docs/providers/aws/r/api_gateway_integration.html.markdown @@ -39,22 +39,91 @@ resource "aws_api_gateway_integration" "MyDemoIntegration" { } ``` +## Lambda integration + +``` +# Variables +variable "myregion" {} +variable "accountId" {} + +# API Gateway +resource "aws_api_gateway_rest_api" "api" { + name = "myapi" +} + +resource "aws_api_gateway_method" "method" { + rest_api_id = "${aws_api_gateway_rest_api.api.id}" + resource_id = "${aws_api_gateway_rest_api.api.root_resource_id}" + http_method = "GET" + authorization = "NONE" +} + +resource "aws_api_gateway_integration" "integration" { + rest_api_id = "${aws_api_gateway_rest_api.api.id}" + resource_id = "${aws_api_gateway_rest_api.api.root_resource_id}" + http_method = "${aws_api_gateway_method.method.http_method}" + integration_http_method = "POST" + type = "AWS" + uri = "arn:aws:apigateway:${var.myregion}:lambda:path/2015-03-31/functions/${aws_lambda_function.lambda.arn}/invocations" +} + +# Lambda +resource "aws_lambda_permission" "apigw_lambda" { + statement_id = "AllowExecutionFromAPIGateway" + action = "lambda:InvokeFunction" + function_name = "${aws_lambda_function.lambda.arn}" + principal = "apigateway.amazonaws.com" + source_arn = "arn:aws:execute-api:${var.myregion}:${var.accountId}:${aws_api_gateway_rest_api.api.id}/*/${aws_api_gateway_method.method.http_method}/" +} + +resource "aws_lambda_function" "lambda" { + filename = "lambda.zip" + function_name = "mylambda" + role = "${aws_iam_role.role.arn}" + handler = "lambda.lambda_handler" + runtime = "python2.7" + source_code_hash = "${base64sha256(file("lambda.zip"))}" +} + +# IAM +resource "aws_iam_role" "role" { + name = "myrole" + assume_role_policy = <