【问题标题】:AWS Cloud Formation template fails with Invalid mapping expression parameter specifiedAWS Cloud Formation 模板失败,并指定了无效的映射表达式参数
【发布时间】:2019-05-05 13:21:19
【问题描述】:

我正在为具有类似 /user/{uid}/cart 的路径的端点开发 AWS Cloud Formation 模板。我需要创建与 HTTP 主机的集成。我一直在尝试将 {uid} 映射到集成请求 URL 路径参数中,如下所示:

            "x-amazon-apigateway-integration": {
              "uri": "http://${stageVariables.httpHost}/user/{uid}/cart",
              "contentHandling": "CONVERT_TO_TEXT",
              "timeoutInMillis": 29000,
              "connectionType": "INTERNET",
              "httpMethod": "PUT",
              "passthroughBehavior": "WHEN_NO_MATCH",
              "type": "HTTP_PROXY",
              "requestParameters": {
                "integration.request.path.uid" : "method.request.path.uid"
              }...

我不断收到此错误,但我不确定自己做错了什么。

Errors found during import: Unable to put integration on 'PUT' for resource at path '/user/{uid}/cart': Invalid mapping expression specified: Validation Result: warnings : [], errors : [Invalid mapping expression parameter specified: method.request.path.uid]

这是完整的模板

{
    "Parameters": {
      "AccessControlAllowOrigin": {
        "Type": "String",
        "Default": "*"
      }
    },
    "Resources": {
      "ConfigApi": {
        "Type": "AWS::ApiGateway::RestApi",
        "Properties": {
          "Body": {
            "swagger": "2.0",
            "tags": [
              {
                "name": "users",
                "description": "secure user calls"
              }
            ],
            "schemes": [
              "https"
            ],
            "paths": {
              "/user/{uid}/cart": {
                "parameters": [
                  {
                    "name": "uid",
                    "in": "path",
                    "description": "user id",
                    "required": true,
                    "type": "string",
                    "format": "uuid"
                  }
                ],
                "put": {
                  "tags": [
                    "users",
                    "cart"
                  ],
                  "summary": "When called, this endpoint completes the user cart and puts their cart into their library",
                  "operationId": "completeusercart",
                  "description": "Completes the user cart\n",
                  "produces": [
                    "application/json"
                  ],
                  "responses": {
                    "200": {
                      "description": "the user identifier",
                      "headers": {
                        "Access-Control-Allow-Origin": {
                          "type": "string"
                        },
                        "Access-Control-Allow-Headers": {
                          "type": "string"
                        }
                      },
                      "schema": {
                        "type": "string"
                      }
                    }
                  },
                  "x-amazon-apigateway-integration": {
                    "uri": "http://${stageVariables.httpHost}/user/{uid}/cart",
                    "contentHandling": "CONVERT_TO_TEXT",
                    "timeoutInMillis": 29000,
                    "connectionType": "INTERNET",
                    "httpMethod": "PUT",
                    "passthroughBehavior": "WHEN_NO_MATCH",
                    "type": "HTTP_PROXY",
                    "requestParameters": {
                      "integration.request.path.uid" : "method.request.path.uid"
                    },
                    "responses": {
                      "default": {
                        "responseModels": {
                          "application/json": "Empty"
                        },
                        "responseParameters": {
                          "method.response.header.Access-Control-Allow-Origin": {
                            "Fn::Sub": "'${AccessControlAllowOrigin}'"
                          },
                          "method.response.header.Access-Control-Allow-Headers": "'Content-Type,X-Amz-Date,Authorization,X-Api-Key,X-Amz-Security-Token'"
                        },
                        "statusCode": "200"
                      }
                    }
                  }
                },
                "options": {
                  "consumes": [
                    "application/json"
                  ],
                  "produces": [
                    "application/json"
                  ],
                  "responses": {
                    "200": {
                      "description": "200 response",
                      "schema": {
                        "$ref": "#/definitions/Empty"
                      },
                      "headers": {
                        "Access-Control-Allow-Origin": {
                          "type": "string"
                        },
                        "Access-Control-Allow-Methods": {
                          "type": "string"
                        },
                        "Access-Control-Allow-Headers": {
                          "type": "string"
                        }
                      }
                    }
                  },
                  "x-amazon-apigateway-integration": {
                    "httpMethod": "OPTIONS",
                    "passthroughBehavior": "WHEN_NO_MATCH",
                    "requestTemplates": {
                      "application/json": "{\"statusCode\": 200}"
                    },
                    "type": "MOCK",
                    "timeoutInMillis": 29000,
                    "responses": {
                      "2\\d{2}": {
                        "responseParameters": {
                          "method.response.header.Access-Control-Allow-Origin": {
                            "Fn::Sub": "'${AccessControlAllowOrigin}'"
                          },
                          "method.response.header.Access-Control-Allow-Methods": "'PUT,OPTIONS'",
                          "method.response.header.Access-Control-Allow-Headers": "'Content-Type,X-Amz-Date,Authorization,X-Api-Key,X-Amz-Security-Token'"
                        },
                        "statusCode": "200"
                      },
                      "4\\d{2}": {
                        "statusCode": "403"
                      },
                      "5\\d{2}": {
                        "statusCode": "403"
                      }
                    }
                  }
                }
              }
            },
            "definitions": {
              "Empty": {
                "type": "object",
                "title": "Empty Schema"
              }
            }
          }
        }
      },
      "ConfigApiStage": {
        "Type": "AWS::ApiGateway::Stage",
        "Properties": {
          "DeploymentId": {
            "Ref": "ApiDeployment"
          },
          "MethodSettings": [
            {
              "DataTraceEnabled": true,
              "HttpMethod": "*",
              "LoggingLevel": "INFO",
              "ResourcePath": "/*"
            }
          ],
          "RestApiId": {
            "Ref": "ConfigApi"
          },
          "Variables": {
            "httpHost": "0.0.0.0"
          },

          "StageName": "LATEST"
        }
      },
      "ApiDeployment": {
        "Type": "AWS::ApiGateway::Deployment",
        "Properties": {
          "RestApiId": {
            "Ref": "ConfigApi"
          },
          "StageName": "DummyStage"
        }
      }
    }
}

感谢您的帮助!

【问题讨论】:

    标签: amazon-web-services amazon-cloudformation aws-api-gateway


    【解决方案1】:

    问题在于parameters 的位置。这些需要在PUT 下而不是path 下。

        "paths": {
            "/user/{uid}/cart": {
                "put": {
                  "tags": [
                    "users",
                    "cart"
                  ],
                  "parameters": [
                  {
                    "name": "uid",
                    "in": "path",
                    "description": "user id",
                    "required": true,
                    "type": "string",
                    "format": "uuid"
                  }
                ],...
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2016-07-07
      • 2014-08-06
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多