简体   繁体   中英

Why does my API Gateway HTTP proxy return 404?

I'm trying to set up API gateway to proxy all requests to a different domain. I set it up using the terraform code below, and everything seems to be in place. But when I try to call it, all I get is {"message":"Not Found"} from API Gateway. Can anyone tell me what I'm doing wrong?

terraform {
  required_providers {
    aws = {
      source  = "hashicorp/aws"
      version = "~> 4.2.0"
    }
  }
  required_version = ">= 1.1.6"
}

provider "aws" {
  region              = "eu-west-1"
}

resource "aws_apigatewayv2_api" "example" {
  name          = "example"
  protocol_type = "HTTP"
}

resource "aws_apigatewayv2_integration" "example" {
  api_id           = aws_apigatewayv2_api.example.id
  integration_type = "HTTP_PROXY"

  integration_method = "ANY"
  integration_uri    = "https://example.com"
}

resource "aws_apigatewayv2_route" "example" {
  api_id    = aws_apigatewayv2_api.example.id
  route_key = "$default"

  target   = "integrations/${aws_apigatewayv2_integration.example.id}"
}

resource "aws_apigatewayv2_stage" "example" {
  api_id   = aws_apigatewayv2_api.example.id
  name     = "example"
}

I've also tried adding access logging to the stage. Nothing shows up in the logs, which might be a hint as to what is going on.

PS. I know there are other ways of doing this, such as CloudFront. Unfortunately it has to be API Gateway in this particular case.

It turns out I was missing a deployment. Easiest way to get up and running:

resource "aws_apigatewayv2_stage" "example" {
  api_id      = aws_apigatewayv2_api.example.id
  name        = "example"
  auto_deploy = true
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM