Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/lua/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Amazon web services 如何在ApiGateway中获取根资源的资源路径?_Amazon Web Services_Terraform_Aws Api Gateway - Fatal编程技术网

Amazon web services 如何在ApiGateway中获取根资源的资源路径?

Amazon web services 如何在ApiGateway中获取根资源的资源路径?,amazon-web-services,terraform,aws-api-gateway,Amazon Web Services,Terraform,Aws Api Gateway,我正在尝试使用terraform更改根资源的GET/OPTIONS方法的api网关中的缓存设置 resource "aws_api_gateway_method_settings" "root_get_method_settings" { rest_api_id = aws_api_gateway_rest_api.default.id stage_name = terraform.workspace method_path = "

我正在尝试使用terraform更改根资源的GET/OPTIONS方法的api网关中的缓存设置

resource "aws_api_gateway_method_settings" "root_get_method_settings" {
  rest_api_id = aws_api_gateway_rest_api.default.id
  stage_name  = terraform.workspace
  method_path = "<root resource path>/GET"

  settings {
    metrics_enabled = true
    logging_level   = "INFO"
    caching_enabled = true
  }
}
路径是
“~1/GET”
。下面是完整的工作示例:


resource "aws_api_gateway_rest_api" "MyDemoAPI" {
  name        = "MyDemoAPI"
  description = "This is my API for demonstration purposes"
}

resource "aws_api_gateway_method" "MyDemoMethod" {
  rest_api_id   = aws_api_gateway_rest_api.MyDemoAPI.id
  resource_id   = aws_api_gateway_rest_api.MyDemoAPI.root_resource_id
  http_method   = "GET"
  authorization = "NONE"
}


resource "aws_api_gateway_deployment" "test" {
  depends_on  = [aws_api_gateway_integration.test]
  rest_api_id = aws_api_gateway_rest_api.MyDemoAPI.id
  stage_name  = "prod"
}

resource "aws_api_gateway_integration" "test" {
  rest_api_id = aws_api_gateway_rest_api.MyDemoAPI.id
  resource_id = aws_api_gateway_rest_api.MyDemoAPI.root_resource_id
  http_method = aws_api_gateway_method.MyDemoMethod.http_method
  type        = "MOCK"
}

resource "aws_api_gateway_method_settings" "root_get_method_settings" {
  rest_api_id = aws_api_gateway_rest_api.MyDemoAPI.id
  stage_name  = "prod"
  method_path = "~1/GET"

  settings {
    metrics_enabled = true
    logging_level   = "INFO"
    caching_enabled = true
  }
  
  depends_on  = [aws_api_gateway_deployment.test]
}

它应该是
/GET
?你试过了吗?是的,我试过了
/GET
GET
。但是这两个都不起作用。你有什么具体的错误吗?“不起作用”不是很具体,信息也不是很丰富。另外,对于要应用设置的GET,您的
aws\U api\U gateway\u方法是什么?
。资源“aws\U api\U gateway\u方法”“根选项\u方法”{rest\u api\u id=aws\u api\u gateway\u rest\u api.default.id resource\u id=aws\u api\u gateway\u rest\u api.default.root\u resource\u id http\u method=“GET”authorization=“NONE”}非常感谢@Marcin。它工作得很好charm@rrajgautam没问题。很高兴它成功了:-)

resource "aws_api_gateway_rest_api" "MyDemoAPI" {
  name        = "MyDemoAPI"
  description = "This is my API for demonstration purposes"
}

resource "aws_api_gateway_method" "MyDemoMethod" {
  rest_api_id   = aws_api_gateway_rest_api.MyDemoAPI.id
  resource_id   = aws_api_gateway_rest_api.MyDemoAPI.root_resource_id
  http_method   = "GET"
  authorization = "NONE"
}


resource "aws_api_gateway_deployment" "test" {
  depends_on  = [aws_api_gateway_integration.test]
  rest_api_id = aws_api_gateway_rest_api.MyDemoAPI.id
  stage_name  = "prod"
}

resource "aws_api_gateway_integration" "test" {
  rest_api_id = aws_api_gateway_rest_api.MyDemoAPI.id
  resource_id = aws_api_gateway_rest_api.MyDemoAPI.root_resource_id
  http_method = aws_api_gateway_method.MyDemoMethod.http_method
  type        = "MOCK"
}

resource "aws_api_gateway_method_settings" "root_get_method_settings" {
  rest_api_id = aws_api_gateway_rest_api.MyDemoAPI.id
  stage_name  = "prod"
  method_path = "~1/GET"

  settings {
    metrics_enabled = true
    logging_level   = "INFO"
    caching_enabled = true
  }
  
  depends_on  = [aws_api_gateway_deployment.test]
}