Skip to content

Instantly share code, notes, and snippets.

@mendhak
Last active November 4, 2024 19:51
Show Gist options
  • Save mendhak/8303d60cbfe8c9bf1905def3ccdb2176 to your computer and use it in GitHub Desktop.
Save mendhak/8303d60cbfe8c9bf1905def3ccdb2176 to your computer and use it in GitHub Desktop.
Terraform - API Gateway with greedy path (proxy+) calling httpbin. Also includes deployment
terraform {
required_providers {
aws = {
source = "hashicorp/aws"
version = "~> 4.0"
}
}
}
provider "aws" {
region = "eu-west-1"
}
resource "aws_api_gateway_rest_api" "MyDemoAPI" {
name = "MyDemoAPI"
description = "This is my API for demonstration purposes"
}
resource "aws_api_gateway_resource" "MyDemoResource" {
rest_api_id = aws_api_gateway_rest_api.MyDemoAPI.id
parent_id = aws_api_gateway_rest_api.MyDemoAPI.root_resource_id
path_part = "{proxy+}"
}
resource "aws_api_gateway_method" "MyDemoMethod" {
rest_api_id = aws_api_gateway_rest_api.MyDemoAPI.id
resource_id = aws_api_gateway_resource.MyDemoResource.id
http_method = "GET"
authorization = "NONE"
request_parameters = {
"method.request.path.proxy" = true
}
}
resource "aws_api_gateway_integration" "MyDemoIntegration" {
rest_api_id = aws_api_gateway_rest_api.MyDemoAPI.id
resource_id = aws_api_gateway_resource.MyDemoResource.id
http_method = aws_api_gateway_method.MyDemoMethod.http_method
type = "HTTP_PROXY"
uri = "https://httpbin.org/anything/{proxy}"
integration_http_method = "GET"
cache_key_parameters = ["method.request.path.proxy"]
timeout_milliseconds = 29000
request_parameters = {
"integration.request.path.proxy" = "method.request.path.proxy"
}
}
resource "aws_api_gateway_deployment" "teststage" {
depends_on = [
aws_api_gateway_integration.MyDemoIntegration
]
rest_api_id = aws_api_gateway_rest_api.MyDemoAPI.id
stage_name = "test"
}
output "api_gateway_test_url" {
value = "${aws_api_gateway_deployment.teststage.invoke_url}/hello/world"
}
@nachomezzadra
Copy link

Thank you!

@luanjpb
Copy link

luanjpb commented Nov 4, 2024

@flarocca Thank you for your contribution. I spent nearly 3 days trying to deploy my function without realizing the problem.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment