Skip to content

Instantly share code, notes, and snippets.

@ritikbanger
Created December 24, 2021 07:31
Show Gist options
  • Save ritikbanger/8e0e8fc640331118f1b8da4fc047bb4c to your computer and use it in GitHub Desktop.
Save ritikbanger/8e0e8fc640331118f1b8da4fc047bb4c to your computer and use it in GitHub Desktop.
AWS API Gateway with greedy path (proxy+) calling httpbin. (Terraform)
resource "aws_api_gateway_rest_api" "MyDemoAWSAPI" {
name = "MyDemoAWSAPI"
description = "This is my API for demonstration purposes"
}
resource "aws_api_gateway_resource" "MyDemoResource" {
rest_api_id = aws_api_gateway_rest_api.MyDemoAWSAPI.id
parent_id = aws_api_gateway_rest_api.MyDemoAWSAPI.root_resource_id
path_part = "{proxy+}"
}
resource "aws_api_gateway_method" "MyDemoMethod" {
rest_api_id = aws_api_gateway_rest_api.MyDemoAWSAPI.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.MyDemoAWSAPI.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 = 28000
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.MyDemoAWSAPI.id
stage_name = "test"
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment