PHPFixing
  • Privacy Policy
  • TOS
  • Ask Question
  • Contact Us
  • Home
  • PHP
  • Programming
  • SQL Injection
  • Web3.0

Friday, June 24, 2022

[FIXED] Why does my API Gateway HTTP proxy return 404?

 June 24, 2022     amazon-web-services, aws-api-gateway, reverse-proxy     No comments   

Issue

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.


Solution

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
}


Answered By - Imre Kerr
Answer Checked By - Mary Flores (PHPFixing Volunteer)
  • Share This:  
  •  Facebook
  •  Twitter
  •  Stumble
  •  Digg
Newer Post Older Post Home

0 Comments:

Post a Comment

Note: Only a member of this blog may post a comment.

Total Pageviews

Featured Post

Why Learn PHP Programming

Why Learn PHP Programming A widely-used open source scripting language PHP is one of the most popular programming languages in the world. It...

Subscribe To

Posts
Atom
Posts
Comments
Atom
Comments

Copyright © PHPFixing