|
| 1 | +resource "aws_api_gateway_rest_api" "example" { |
| 2 | + name = "ServerlessExample" |
| 3 | + description = "Terraform Serverless Application Example" |
| 4 | +} |
| 5 | + |
| 6 | +resource "aws_api_gateway_resource" "proxy" { |
| 7 | + rest_api_id = "${aws_api_gateway_rest_api.example.id}" |
| 8 | + parent_id = "${aws_api_gateway_rest_api.example.root_resource_id}" |
| 9 | + path_part = "{proxy+}" |
| 10 | +} |
| 11 | + |
| 12 | +resource "aws_api_gateway_method" "proxy" { |
| 13 | + rest_api_id = "${aws_api_gateway_rest_api.example.id}" |
| 14 | + resource_id = "${aws_api_gateway_resource.proxy.id}" |
| 15 | + http_method = "ANY" |
| 16 | + authorization = "NONE" |
| 17 | +} |
| 18 | + |
| 19 | +resource "aws_api_gateway_integration" "lambda" { |
| 20 | + rest_api_id = "${aws_api_gateway_rest_api.example.id}" |
| 21 | + resource_id = "${aws_api_gateway_method.proxy.resource_id}" |
| 22 | + http_method = "${aws_api_gateway_method.proxy.http_method}" |
| 23 | + |
| 24 | + integration_http_method = "POST" |
| 25 | + type = "AWS_PROXY" |
| 26 | + uri = "${aws_lambda_function.example.invoke_arn}" |
| 27 | +} |
| 28 | + |
| 29 | +resource "aws_api_gateway_method" "proxy_root" { |
| 30 | + rest_api_id = "${aws_api_gateway_rest_api.example.id}" |
| 31 | + resource_id = "${aws_api_gateway_rest_api.example.root_resource_id}" |
| 32 | + http_method = "ANY" |
| 33 | + authorization = "NONE" |
| 34 | +} |
| 35 | + |
| 36 | +resource "aws_api_gateway_integration" "lambda_root" { |
| 37 | + rest_api_id = "${aws_api_gateway_rest_api.example.id}" |
| 38 | + resource_id = "${aws_api_gateway_method.proxy_root.resource_id}" |
| 39 | + http_method = "${aws_api_gateway_method.proxy_root.http_method}" |
| 40 | + |
| 41 | + integration_http_method = "POST" |
| 42 | + type = "AWS_PROXY" |
| 43 | + uri = "${aws_lambda_function.example.invoke_arn}" |
| 44 | +} |
| 45 | + |
| 46 | +resource "aws_api_gateway_deployment" "example" { |
| 47 | + depends_on = [ |
| 48 | + "aws_api_gateway_integration.lambda", |
| 49 | + "aws_api_gateway_integration.lambda_root", |
| 50 | + ] |
| 51 | + |
| 52 | + rest_api_id = "${aws_api_gateway_rest_api.example.id}" |
| 53 | + stage_name = "test" |
| 54 | +} |
| 55 | + |
| 56 | + |
| 57 | +output "base_url" { |
| 58 | + value = "${aws_api_gateway_deployment.example.invoke_url}" |
| 59 | +} |
0 commit comments