我已经尝试将以下内容添加到我目前正在使用的apigateway API设置中
resource "aws_api_gateway_method" "enable_head_request" {
provider = "aws.default"
rest_api_id = "${aws_api_gateway_rest_api.petshop.id}"
resource_id = "${aws_api_gateway_rest_api.petshop.root_resource_id}"
http_method = "HEAD"
authorization = "NONE"
# api_key_required = "False"
}
resource "aws_api_gateway_integration" "enable_head_request" {
provider = "aws.default"
rest_api_id = "${aws_api_gateway_rest_api.petshop.id}"
resource_id = "${aws_api_gateway_rest_api.petshop.root_resource_id}"
http_method = "${aws_api_gateway_method.enable_head_request.http_method}"
integration_http_method = "POST"
type = "AWS_PROXY"
uri = "${aws_lambda_function.petshop.invoke_arn}"
}
resource "aws_api_gateway_method_response" "200_for_head_request" {
provider = "aws.default"
rest_api_id = "${aws_api_gateway_rest_api.petshop.id}"
resource_id = "${aws_api_gateway_rest_api.petshop.root_resource_id}"
http_method = "${aws_api_gateway_method.enable_head_request.http_method}"
status_code = "200"
}
但是在部署并尝试卷曲端点后,我得到了;
curl --head https://test.com
HTTP/1.1 403 Forbidden
Date: Thu, 01 Mar 2018 18:47:07 GMT
Content-Type: application/json
Content-Length: 42
Connection: keep-alive
x-amzn-RequestId: f1811ce9-1d80-11e8-b15c-cf44af523470
x-amzn-ErrorType: MissingAuthenticationTokenException
编辑:问题确实是没有重新部署部署。但我发现在我的回答中提到了更好的方法。
问题是部署没有重新部署。这是一个比链接问题更好的方法
resource "aws_api_gateway_deployment" "petshop" {
provider = "aws.default"
stage_description = "${md5(file("apigateway.tf"))}"
rest_api_id = "${aws_api_gateway_rest_api.petshop.id}"
stage_name = "prod"
}
这样可以节省您在每次微小更改时的重新部署,并且只会由apigateway.tf
文件中的更改触发