简体   繁体   English

禁止使用Amazon API Gateway 403

[英]Amazon API Gateway 403 Forbidden

Recently, I used the Amazon API Gateway .I created an api ,but the API failed all the time. 最近,我使用了Amazon API Gateway。我创建了一个api,但该API始终失败。 At the beginning,I didn't add request headers.The result that API responsed is as follows: 一开始,我没有添加请求标头。API响应的结果如下:

HTTP/1.1 403 Forbidden    
{"message":null, "type": "ACCESS_DENIED", "status":"", "other":"" }

Then ,I added a header which named host,the result changed. 然后,我添加了一个名为host的标题,结果发生了变化。

HTTP/1.1 403 Forbidden
{"message":"Forbidden"}

I didn't use other AWS. 我没有使用其他AWS。 I set the authorization is none and the API key required is false. 我将授权设置为无,并且所需的API密钥为false。 enter image description here Could you help me? 在此处输入图片描述,您能帮我吗? Thanks! 谢谢!

A cause of {"message":"Forbidden"} which I had which had me stumped was that I had not deployed my API. 令我感到困惑的{"message":"Forbidden"}原因是我没有部署我的API。

For anyone having this issue, check if your gateway has been deployed. 对于遇到此问题的任何人,请检查您的网关是否已部署。 First you will need a Stage , with which you can click Deploy API from the Actions dropdown, selecting your stage. 首先,您将需要一个Stage ,从中可以从Actions下拉菜单中单击Deploy API ,选择您的阶段。

Deploying will give you an invoke_url , (which ends in /{stage-name} . 部署将为您提供invoke_url (以/{stage-name}结尾。

For those using Terraform.... 对于那些使用Terraform的人...

You can define an aws_api_gateway_stage which depends on aws_api_gateway_deployment . 您可以定义一个aws_api_gateway_stage取决于aws_api_gateway_deployment There is a known issue, at the time of writing , where the deployment doesn't re-trigger, which was the original cause of my forbidden error. 撰写本文时 ,存在一个已知问题,其中部署不会重新触发,这是我禁止的错误的最初原因。

To fix this and get the deployment to run everytime a change has been made, add to aws_api_gateway_deployment : 要解决此问题并使部署在每次进行更改时运行,请添加到aws_api_gateway_deployment

resource "aws_api_gateway_deployment" "gateway-deployment" {
  ...

  stage_description = "Terraform hash ${md5(join(",", local.all_resources))}"

  lifecycle {
    create_before_destroy = true
  }
}

locals {
  all_resources = [
    "${aws_api_gateway_resource.simulator-gateway-resource.path}:${aws_api_gateway_method.simulator-gateway-method.http_method}:${aws_api_gateway_integration.simulator-gateway-integration.uri}",
  ]
}```

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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