在aws_api_gateway_method_settings logging_level上的BadRequest

时间:2018-08-04 15:11:03

标签: terraform

我在“ terraform apply”时遇到以下错误:

*`aws_api_gateway_method_settings.api_gateway_method_settings_property_lambda: Updating API Gateway Stage failed: BadRequestException: Invalid method setting path: /property/ANY/metrics/enabled. Must be one of: [/deploymentId, /description, /cacheClusterEnabled, /cacheClusterSize, /clientCertificateId, /accessLogSettings, /accessLogSettings/destinationArn, /accessLogSettings/format, /{resourcePath}/{httpMethod}/metrics/enabled, /{resourcePath}/{httpMethod}/logging/dataTrace, /{resourcePath}/{httpMethod}/logging/loglevel, /{resourcePath}/{httpMethod}/throttling/burstLimit/{resourcePath}/{httpMethod}/throttling/rateLimit/{resourcePath}/{httpMethod}/caching/ttlInSeconds, /{resourcePath}/{httpMethod}/caching/enabled, /{resourcePath}/{httpMethod}/caching/dataEncrypted, /{resourcePath}/{httpMethod}/caching/requireAuthorizationForCacheControl, /{resourcePath}/{httpMethod}/caching/unauthorizedCacheControlHeaderStrategy, /*/*/metrics/enabled, /*/*/logging/dataTrace, /*/*/logging/loglevel, /*/*/throttling/burstLimit /*/*/throttling/rateLimit /*/*/caching/ttlInSeconds, /*/*/caching/enabled, /*/*/caching/dataEncrypted, /*/*/caching/requireAuthorizationForCacheControl, /*/*/caching/unauthorizedCacheControlHeaderStrategy, /variables/{variable_name}, /tracingEnabled]`
    status code: 400, request id: 7f7ec35e-97ec-11e8-b95f-7f3d88cdbe6b

我看了在logging_level上可以找到的所有文档。我只能找到以其编码方式进行编码的示例。而且我找不到有关此特定错误的任何信息。我的地形:

resource "aws_iam_role" "role_lambda_property" {
  name = "${local.project-prefix}-role-lambda-property"
  assume_role_policy = <<EOF
{
"Version": "2012-10-17",
"Statement": [
{
    "Action": "sts:AssumeRole",
    "Principal": {
        "Service":  [
            "lambda.amazonaws.com",
            "apigateway.amazonaws.com"
        ]
    },
    "Effect": "Allow",
    "Sid": ""
}
]
}
EOF
}

resource "aws_iam_role_policy" "policy_property_lambda" {
  name = "${local.project-prefix}-policy-property-lambda"
  role = "${aws_iam_role.role_lambda_property.id}"
policy = <<EOF
{
  "Version": "2012-10-17",
  "Statement":
  [
    {
      "Effect": "Allow",
      "Action": [
        "logs:CreateLogGroup",
        "logs:CreateLogStream",
        "logs:PutLogEvents"
      ],
      "Resource": "arn:aws:logs:*:*:*"
  },
  {
    "Effect": "Allow",
    "Action": [
      "s3:GetObject",
      "s3:GetObjectVersion",
      "s3:PutObject",
      "s3:DeleteObject"
    ],
    "Resource": "arn:aws:s3:::${local.s3_bucket_lambda_name}/*"
  },
  {
    "Effect": "Allow",
    "Action": [
      "s3:GetObject",
      "s3:GetObjectVersion",
      "s3:PutObject",
      "s3:DeleteObject",
      "s3:ListBucket"
    ],
    "Resource": "arn:aws:s3:::${local.s3_bucket_library_name}/*"
  }
]
}
EOF
}

resource "aws_cloudwatch_log_group" "cloudwatch_log_group_useast1" {
  name = "${local.project_name}-cloudwatch-log-group-useast1"

  tags {
    Environment = "${var.short_env}"
  }
}

resource "aws_api_gateway_stage" "api_gateway_stage_property_lambda" {
  stage_name = "${var.short_env}"
  rest_api_id = 
"${aws_api_gateway_rest_api.api_gateway_rest_api_property_lambda.id}"
    deployment_id =
  "${aws_api_gateway_deployment.api_gateway_deployment_property_lambda.id}"
}

    resource "aws_api_gateway_method_settings" 
      "api_gateway_method_settings_property_lambda" {
      depends_on = [
        "aws_api_gateway_deployment.api_gateway_deployment_property_lambda"
      ]
      rest_api_id = 
    "${aws_api_gateway_rest_api.api_gateway_rest_api_property_lambda.id}"
      stage_name  =   "${aws_api_gateway_deployment.api_gateway_deployment_property_lambda.stage_name}"
      method_path = "${aws_api_gateway_resource.api_gateway_resource_property_lambda.path_part}/${aws_api_gateway_method.api_gateway_method_get_property_lambda.http_method}"
      settings {
        metrics_enabled = true
        logging_level   = "INFO"
      }
    }
resource "aws_api_gateway_rest_api" 
  "api_gateway_rest_api_property_lambda" {
  name = "${local.project-prefix}-gateway-rest-api-property"
  description = "API Gateway for library-core property (application and message) end points"
}

resource "aws_api_gateway_resource" 
  "api_gateway_resource_property_lambda" {
  rest_api_id = "${aws_api_gateway_rest_api.api_gateway_rest_api_property_lambda.id}"
  parent_id = "${aws_api_gateway_rest_api.api_gateway_rest_api_property_lambda.root_resource_id}"
  path_part = "property"
}

resource "aws_api_gateway_method" 
  "api_gateway_method_get_property_lambda" {
  http_method = "ANY"
  authorization = "NONE"
  rest_api_id = 
  "${aws_api_gateway_rest_api.api_gateway_rest_api_property_lambda.id}"
  resource_id = 
  "${aws_api_gateway_resource.api_gateway_resource_property_lambda.id}"
  request_parameters = {"method.request.querystring.type" = true}
}

resource "aws_api_gateway_integration" 
  "api_gateway_integration_get_property_lambda" {
  rest_api_id = 
 "${aws_api_gateway_rest_api.api_gateway_rest_api_property_lambda.id}"
  resource_id = 
 "${aws_api_gateway_resource.api_gateway_resource_property_lambda.id}"
  http_method = "${aws_api_gateway_method.api_gateway_method_get_property_lambda.http_method}"
  type = "AWS_PROXY"
  uri = "arn:aws:apigateway:${var.region}:lambda:path/2015-03-31/functions/arn:aws:lambda:${var.region}:${var.accountId}:function:${aws_lambda_function.function_property_lambda.function_name}/invocations"
  integration_http_method = "ANY"
}

resource "aws_api_gateway_integration_response" 
  "api_gateway_integration_response_get_property_lambda" {
  depends_on = [
    "aws_api_gateway_method.api_gateway_method_get_property_lambda","aws_api_gateway_integration.api_gateway_integration_get_property_lambda"
  ]
  rest_api_id = "${aws_api_gateway_rest_api.api_gateway_rest_api_property_lambda.id}"
  resource_id = "${aws_api_gateway_resource.api_gateway_resource_property_lambda.id}"
  http_method = "${aws_api_gateway_method.api_gateway_method_get_property_lambda.http_method}"
  status_code = "200"
  response_templates = {
    "application/json" = ""
  }
}

resource "aws_api_gateway_deployment" "api_gateway_deployment_property_lambda" {
  depends_on = [
    "aws_api_gateway_method.api_gateway_method_get_property_lambda",
"aws_api_gateway_integration.api_gateway_integration_get_property_lambda"
  ]
  rest_api_id = "${aws_api_gateway_rest_api.api_gateway_rest_api_property_lambda.id}"
  stage_name = "${aws_cloudwatch_log_group.cloudwatch_log_group_useast1.id}"
}



resource "aws_api_gateway_method_response" 
  "api_gateway_method_response_get_property_lambda" {
  depends_on = ["aws_api_gateway_integration_response.api_gateway_integration_response_get_property_lambda"]
  rest_api_id = "${aws_api_gateway_rest_api.api_gateway_rest_api_property_lambda.id}"
  resource_id = "${aws_api_gateway_resource.api_gateway_resource_property_lambda.id}"
  http_method = "${aws_api_gateway_method.api_gateway_method_get_property_lambda.http_method}"
  status_code = "200"
  response_models = {
    "application/json" = "Empty"
  }
}

有人知道我在做什么错吗?看来问题是特定于地形的。也许就像我缺少某种我应该做的设置或缺少terraform软件包一样?

1 个答案:

答案 0 :(得分:0)

已解决。问题是我正在使用:

resource "aws_api_gateway_method" "api_gateway_method_get_property_lambda" {
  http_method = "ANY"

当我通过以下方式访问它时:

resource "aws_api_gateway_method_settings" 
  "api_gateway_method_settings_property_lambda" {
  depends_on = [
    "aws_api_gateway_deployment.api_gateway_deployment_property_lambda"
  ]
  rest_api_id = 
    "${aws_api_gateway_rest_api.api_gateway_rest_api_property_lambda.id}"
 stage_name = "${aws_api_gateway_deployment.api_gateway_deployment_property_lambda.stage_name}"  
method_path = "${aws_api_gateway_resource.api_gateway_resource_property_lambda.path_part}/${aws_api_gateway_method.api_gateway_method_get_property_lambda.http_method}"

它显然不支持将“ ANY”作为HTTP方法更改为:

resource "aws_api_gateway_method" "api_gateway_method_get_property_lambda" {
  http_method = "GET"

我没有得到错误。