amazon-web-services - AWS Cloud Formation 模板失败,指定的映射表达式参数无效

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

我正在为具有 /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"
        }
      }
    }
}

感谢您的帮助!

最佳答案

问题出在参数的位置。这些需要位于 PUT 下,而不是位于 path 下。

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

关于amazon-web-services - AWS Cloud Formation 模板失败,指定的映射表达式参数无效,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53607465/

相关文章:

amazon-web-services - 在Amazon EC2实例中设置SSH超时-CentOS 7

yaml - Cloudformation Unresolved 资源依赖性

amazon-web-services - lambda 函数未使用 AWS 中的 cloudformation 和 pipeline 进行更新

aws-lambda - 用于 Lambda 代理集成的 Terraform API 网关

amazon-web-services - CodeDeploy 配置以覆盖文件

amazon-web-services - 如何在 AWS 中的特定时间触发 Lambda 函数?

amazon-web-services - 无法在 Postman 中测试 Cognito 认证的 API 网关调用(它是一个 ADMIN_NO_SRP_AUTH 池)

push-notification - AWS Lambda 和 Google Drive 推送通知集成可能吗?

java - Cassandra部署集群失败

amazon-rds - AWS Cloudformation 支持性能洞察