Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

bug: API Gateway Proxy does not forward the backend response code (always returns 200) #10461

Closed
1 task done
dmitriyklyuzov opened this issue Mar 14, 2024 · 4 comments · Fixed by #10583
Closed
1 task done
Assignees
Labels
aws:apigateway Amazon API Gateway status: backlog Triaged but not yet being worked on type: bug Bug report

Comments

@dmitriyklyuzov
Copy link

dmitriyklyuzov commented Mar 14, 2024

Is there an existing issue for this?

  • I have searched the existing issues

Current Behavior

The LocalStack-based API Gateway does not forward the HTTP code from the backend and instead always returns a 200 response, regardless of what the backend response code was:
Screenshot 2024-03-14 at 10 20 17 AM

Expected Behavior

According to the AWS Documentation, For proxy integrations, API Gateway automatically passes the backend response to the method response. In other words, if the backend is returning an HTTP 401, the API Gateway should also return a 401 (not 200), as confirmed when deploying the same infrastructure to AWS:
Screenshot 2024-03-14 at 10 20 21 AM

How are you starting LocalStack?

With a docker run command

Steps To Reproduce

How are you starting localstack (e.g., bin/localstack command, arguments, or docker-compose.yml)

docker run localstack/localstack

Terraform code

resource "aws_api_gateway_rest_api" "root" {
  name        = "test-api-gw"
  description = "Test API Gateway"
}

resource "aws_api_gateway_resource" "icat_resource" {
  rest_api_id = aws_api_gateway_rest_api.root.id
  parent_id   = aws_api_gateway_rest_api.root.root_resource_id
  path_part   = "icat"
}

resource "aws_api_gateway_resource" "icat_proxy" {
  rest_api_id = aws_api_gateway_rest_api.root.id
  parent_id   = aws_api_gateway_resource.icat_resource.id
  path_part   = "{proxy+}"
}

resource "aws_api_gateway_method" "icat_api_method" {
  rest_api_id   = aws_api_gateway_rest_api.root.id
  resource_id   = aws_api_gateway_resource.icat_proxy.id
  http_method   = "ANY"
  authorization = "NONE"

  request_parameters = {
    "method.request.path.proxy" = true
  }
}

resource "aws_api_gateway_integration" "icat_integration" {
  rest_api_id             = aws_api_gateway_rest_api.root.id
  resource_id             = aws_api_gateway_resource.icat_proxy.id
  http_method             = aws_api_gateway_method.icat_api_method.http_method
  integration_http_method = "ANY"
  type                    = "HTTP_PROXY"
  uri                     = "<any public endpoint that does not return a 200>"

  request_parameters = {
    "integration.request.path.proxy" = "method.request.path.proxy"
  }
}

resource "aws_api_gateway_method_response" "icat_method_response" {
  rest_api_id = aws_api_gateway_rest_api.root.id
  resource_id = aws_api_gateway_resource.icat_proxy.id
  http_method = aws_api_gateway_method.icat_api_method.http_method
  status_code = "200"

  response_models = {
    "application/json" = "Empty"
  }
}

resource "aws_api_gateway_integration_response" "icat_integration_response" {
  rest_api_id = aws_api_gateway_rest_api.root.id
  resource_id = aws_api_gateway_resource.icat_proxy.id
  http_method = aws_api_gateway_method.icat_api_method.http_method
  status_code = aws_api_gateway_method_response.icat_method_response.status_code
}

resource "aws_api_gateway_deployment" "icat_deployment" {
  depends_on = [
    aws_api_gateway_method_response.icat_method_response,
    aws_api_gateway_integration_response.icat_integration_response,
  ]

  rest_api_id = aws_api_gateway_rest_api.root.id
  stage_name  = "local"
}

output "api_gateway_execution_url" {
  value = "https://${aws_api_gateway_rest_api.root.id}.execute-api.localhost.localstack.cloud:4566/local/"
}

Init && apply
tflocal init && tflocal apply

Environment

- OS: MacOS
- LocalStack: latest

Anything else?

No response

@dmitriyklyuzov dmitriyklyuzov added status: triage needed Requires evaluation by maintainers type: bug Bug report labels Mar 14, 2024
@localstack-bot
Copy link
Collaborator

Welcome to LocalStack! Thanks for reporting your first issue and our team will be working towards fixing the issue for you or reach out for more background information. We recommend joining our Slack Community for real-time help and drop a message to LocalStack Pro Support if you are a Pro user! If you are willing to contribute towards fixing this issue, please have a look at our contributing guidelines and our contributing guide.

@bentsku bentsku added aws:apigateway Amazon API Gateway status: backlog Triaged but not yet being worked on and removed status: triage needed Requires evaluation by maintainers labels Mar 14, 2024
@dmitriyklyuzov dmitriyklyuzov changed the title bug: API Gateway Proxy Integration does not automatically pass the backend response to the method response bug: API Gateway Proxy Integration does not forward the backend response code (always returns 200) Mar 14, 2024
@dmitriyklyuzov dmitriyklyuzov changed the title bug: API Gateway Proxy Integration does not forward the backend response code (always returns 200) bug: API Gateway Proxy does not forward the backend response code (always returns 200) Mar 14, 2024
@cloutierMat cloutierMat self-assigned this Mar 21, 2024
@cloutierMat cloutierMat linked a pull request Apr 2, 2024 that will close this issue
@dmitriyklyuzov
Copy link
Author

Thanks for fixing this! Any ETA on when this will be released?

@cloutierMat
Copy link
Contributor

Hi @dmitriyklyuzov, Thank you for bringing that issue to our attention.
The fix should already be available in the latest Docker image.

@dmitriyklyuzov
Copy link
Author

hi @cloutierMat awesome - just confirmed this works. Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
aws:apigateway Amazon API Gateway status: backlog Triaged but not yet being worked on type: bug Bug report
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants