【问题标题】:AWS Mysfits - Invalid HTTP Endpoint API Gateway PushAWS Mysfits - 无效的 HTTP 端点 API 网关推送
【发布时间】:2020-02-08 00:48:24
【问题描述】:

在 AWS Mythical Mysfits 教程的第 4 单元中,在使用所有替换 me 更新 swagger 文档后,我无法推送 API 更改。我已按照本节的说明操作了 3 次。

参考号:https://aws.amazon.com/getting-started/projects/build-modern-app-fargate-lambda-dynamodb-python/module-four/

我正在通过 Cloud9 运行以下命令:

aws apigateway import-rest-api --parameters endpointConfigurationTypes=REGIONAL --body file://~/environment/aws-modern-application-workshop/module-4/aws-cli/api-swagger.json --fail-on-warnings

使用 api-swagger-json:

{
    "swagger": 2.0,
    "info": {
        "title": "MysfitsApi"
    },
    "securityDefinitions": {
        "MysfitsUserPoolAuthorizer": {
            "type": "apiKey",
            "name": "Authorization",
            "in": "header",
            "x-amazon-apigateway-authtype": "cognito_user_pools",
            "x-amazon-apigateway-authorizer": {
                "type": "COGNITO_USER_POOLS",
                "providerARNs": [
                    "arn:aws:cognito-idp:us-east-2:730082756200:userpool/us-east-2_jFYjOTZRU"
                ]
            }
        }
    },
    "paths": {
        "/": {
            "get": {
                "responses": {
                    "200": {
                        "description": "Default response for CORS method",
                        "headers": {
                            "Access-Control-Allow-Headers": {
                                "type": "string"
                            },
                            "Access-Control-Allow-Methods": {
                                "type": "string"
                            },
                            "Access-Control-Allow-Origin": {
                                "type": "string"
                            }
                        }
                    }
                },
                "x-amazon-apigateway-integration": {
                    "connectionType": "VPC_LINK",
                    "responses": {
                        "default": {
                            "statusCode": "200",
                            "responseParameters": {
                                "method.response.header.Access-Control-Allow-Headers": "'Content-Type,X-Amz-Date,Authorization,X-Api-Key'",
                                "method.response.header.Access-Control-Allow-Methods": "'*'",
                                "method.response.header.Access-Control-Allow-Origin": "'*'"
                            }
                        }
                    },
                    "connectionId": "wg0305",
                    "httpMethod": "GET",
                    "type": "HTTP_PROXY",
                    "uri": "mysfits-nlb-52741b4979bb0b50.elb.us-east-2.amazonaws.com"
                }
            },
            "options": {
                "summary": "CORS support",
                "description": "Enable CORS by returning correct headers\n",
                "consumes": [
                    "application/json"
                ],
                "produces": [
                    "application/json"
                ],
                "tags": [
                    "CORS"
                ],
                "x-amazon-apigateway-integration": {
                    "type": "mock",
                    "requestTemplates": {
                        "application/json": "{\n  \"statusCode\" : 200\n}\n"
                    },
                    "responses": {
                        "default": {
                            "statusCode": "200",
                            "responseParameters": {
                                "method.response.header.Access-Control-Allow-Headers": "'Content-Type,X-Amz-Date,Authorization,X-Api-Key'",
                                "method.response.header.Access-Control-Allow-Methods": "'*'",
                                "method.response.header.Access-Control-Allow-Origin": "'*'"
                            },
                            "responseTemplates": {
                                "application/json": "{}\n"
                            }
                        }
                    }
                },
                "responses": {
                    "200": {
                        "description": "Default response for CORS method",
                        "headers": {
                            "Access-Control-Allow-Headers": {
                                "type": "string"
                            },
                            "Access-Control-Allow-Methods": {
                                "type": "string"
                            },
                            "Access-Control-Allow-Origin": {
                                "type": "string"
                            }
                        }
                    }
                }
            }
        },
        "/mysfits": {
            "get": {
                "responses": {
                    "200": {
                        "description": "Default response for CORS method",
                        "headers": {
                            "Access-Control-Allow-Headers": {
                                "type": "string"
                            },
                            "Access-Control-Allow-Methods": {
                                "type": "string"
                            },
                            "Access-Control-Allow-Origin": {
                                "type": "string"
                            }
                        }
                    }
                },
                "x-amazon-apigateway-integration": {
                    "connectionType": "VPC_LINK",
                    "connectionId": "wg0305",
                    "httpMethod": "GET",
                    "type": "HTTP_PROXY",
                    "uri": "http://mysfits-nlb-52741b4979bb0b50.elb.us-east-2.amazonaws.com/mysfits",
                    "responses": {
                        "default": {
                            "statusCode": "200",
                            "responseParameters": {
                                "method.response.header.Access-Control-Allow-Headers": "'Content-Type,X-Amz-Date,Authorization,X-Api-Key'",
                                "method.response.header.Access-Control-Allow-Methods": "'*'",
                                "method.response.header.Access-Control-Allow-Origin": "'*'"
                            }
                        }
                    }
                }
            },
            "options": {
                "summary": "CORS support",
                "description": "Enable CORS by returning correct headers\n",
                "consumes": [
                    "application/json"
                ],
                "produces": [
                    "application/json"
                ],
                "tags": [
                    "CORS"
                ],
                "x-amazon-apigateway-integration": {
                    "type": "mock",
                    "requestTemplates": {
                        "application/json": "{\n  \"statusCode\" : 200\n}\n"
                    },
                    "responses": {
                        "default": {
                            "statusCode": "200",
                            "responseParameters": {
                                "method.response.header.Access-Control-Allow-Headers": "'Content-Type,X-Amz-Date,Authorization,X-Api-Key'",
                                "method.response.header.Access-Control-Allow-Methods": "'*'",
                                "method.response.header.Access-Control-Allow-Origin": "'*'"
                            },
                            "responseTemplates": {
                                "application/json": "{}\n"
                            }
                        }
                    }
                },
                "responses": {
                    "200": {
                        "description": "Default response for CORS method",
                        "headers": {
                            "Access-Control-Allow-Headers": {
                                "type": "string"
                            },
                            "Access-Control-Allow-Methods": {
                                "type": "string"
                            },
                            "Access-Control-Allow-Origin": {
                                "type": "string"
                            }
                        }
                    }
                }
            }
        },
        "/mysfits/{mysfitId}": {
            "get": {
                "parameters": [{
                    "name": "mysfitId",
                    "in": "path",
                    "required": true,
                    "type": "string"
                }],
                "responses": {
                    "200": {
                        "description": "Default response for CORS method",
                        "headers": {
                            "Access-Control-Allow-Headers": {
                                "type": "string"
                            },
                            "Access-Control-Allow-Methods": {
                                "type": "string"
                            },
                            "Access-Control-Allow-Origin": {
                                "type": "string"
                            }
                        }
                    }
                },
                "x-amazon-apigateway-integration": {
                    "requestParameters": {
                        "integration.request.path.mysfitId": "method.request.path.mysfitId"
                    },
                    "connectionType": "VPC_LINK",
                    "connectionId": "wg0305",
                    "httpMethod": "GET",
                    "type": "HTTP_PROXY",
                    "uri": "http://mysfits-nlb-52741b4979bb0b50.elb.us-east-2.amazonaws.com/mysfits/{mysfitId}",
                    "responses": {
                        "default": {
                            "statusCode": "200",
                            "responseParameters": {
                                "method.response.header.Access-Control-Allow-Headers": "'Content-Type,X-Amz-Date,Authorization,X-Api-Key'",
                                "method.response.header.Access-Control-Allow-Methods": "'*'",
                                "method.response.header.Access-Control-Allow-Origin": "'*'"
                            }
                        }
                    }
                }
            },
            "options": {
                "summary": "CORS support",
                "description": "Enable CORS by returning correct headers\n",
                "consumes": [
                    "application/json"
                ],
                "produces": [
                    "application/json"
                ],
                "tags": [
                    "CORS"
                ],
                "x-amazon-apigateway-integration": {
                    "type": "mock",
                    "requestTemplates": {
                        "application/json": "{\n  \"statusCode\" : 200\n}\n"
                    },
                    "responses": {
                        "default": {
                            "statusCode": "200",
                            "responseParameters": {
                                "method.response.header.Access-Control-Allow-Headers": "'Content-Type,X-Amz-Date,Authorization,X-Api-Key'",
                                "method.response.header.Access-Control-Allow-Methods": "'*'",
                                "method.response.header.Access-Control-Allow-Origin": "'*'"
                            },
                            "responseTemplates": {
                                "application/json": "{}\n"
                            }
                        }
                    }
                },
                "responses": {
                    "200": {
                        "description": "Default response for CORS method",
                        "headers": {
                            "Access-Control-Allow-Headers": {
                                "type": "string"
                            },
                            "Access-Control-Allow-Methods": {
                                "type": "string"
                            },
                            "Access-Control-Allow-Origin": {
                                "type": "string"
                            }
                        }
                    }
                }
            }
        },
        "/mysfits/{mysfitId}/adopt": {
            "post": {
                "parameters": [{
                    "name": "mysfitId",
                    "in": "path",
                    "required": true,
                    "type": "string"
                }],
                "responses": {
                    "200": {
                        "description": "Default response for CORS method",
                        "headers": {
                            "Access-Control-Allow-Headers": {
                                "type": "string"
                            },
                            "Access-Control-Allow-Methods": {
                                "type": "string"
                            },
                            "Access-Control-Allow-Origin": {
                                "type": "string"
                            }
                        }
                    }
                },
                "security": [{
                    "MysfitsUserPoolAuthorizer": [

                    ]
                }],
                "x-amazon-apigateway-integration": {
                    "requestParameters": {
                        "integration.request.path.mysfitId": "method.request.path.mysfitId"
                    },
                    "connectionType": "VPC_LINK",
                    "connectionId": "wg0305",
                    "httpMethod": "POST",
                    "type": "HTTP_PROXY",
                    "uri": "http://mysfits-nlb-52741b4979bb0b50.elb.us-east-2.amazonaws.com/mysfits/{mysfitId}/adopt",
                    "responses": {
                        "default": {
                            "statusCode": "200",
                            "responseParameters": {
                                "method.response.header.Access-Control-Allow-Headers": "'Content-Type,X-Amz-Date,Authorization,X-Api-Key'",
                                "method.response.header.Access-Control-Allow-Methods": "'*'",
                                "method.response.header.Access-Control-Allow-Origin": "'*'"
                            }
                        }
                    }
                }
            },
            "options": {
                "summary": "CORS support",
                "description": "Enable CORS by returning correct headers\n",
                "consumes": [
                    "application/json"
                ],
                "produces": [
                    "application/json"
                ],
                "tags": [
                    "CORS"
                ],
                "x-amazon-apigateway-integration": {
                    "type": "mock",
                    "requestTemplates": {
                        "application/json": "{\n  \"statusCode\" : 200\n}\n"
                    },
                    "responses": {
                        "default": {
                            "statusCode": "200",
                            "responseParameters": {
                                "method.response.header.Access-Control-Allow-Headers": "'Content-Type,X-Amz-Date,Authorization,X-Api-Key'",
                                "method.response.header.Access-Control-Allow-Methods": "'*'",
                                "method.response.header.Access-Control-Allow-Origin": "'*'"
                            },
                            "responseTemplates": {
                                "application/json": "{}\n"
                            }
                        }
                    }
                },
                "responses": {
                    "200": {
                        "description": "Default response for CORS method",
                        "headers": {
                            "Access-Control-Allow-Headers": {
                                "type": "string"
                            },
                            "Access-Control-Allow-Methods": {
                                "type": "string"
                            },
                            "Access-Control-Allow-Origin": {
                                "type": "string"
                            }
                        }
                    }
                }
            }
        },
        "/mysfits/{mysfitId}/like": {
            "post": {
                "parameters": [{
                    "name": "mysfitId",
                    "in": "path",
                    "required": true,
                    "type": "string"
                }],
                "responses": {
                    "200": {
                        "description": "Default response for CORS method",
                        "headers": {
                            "Access-Control-Allow-Headers": {
                                "type": "string"
                            },
                            "Access-Control-Allow-Methods": {
                                "type": "string"
                            },
                            "Access-Control-Allow-Origin": {
                                "type": "string"
                            }
                        }
                    }
                },
                "security": [{
                    "MysfitsUserPoolAuthorizer": [

                    ]
                }],
                "x-amazon-apigateway-integration": {
                    "responses": {
                        "default": {
                            "statusCode": "200",
                            "responseParameters": {
                                "method.response.header.Access-Control-Allow-Headers": "'Content-Type,X-Amz-Date,Authorization,X-Api-Key'",
                                "method.response.header.Access-Control-Allow-Methods": "'*'",
                                "method.response.header.Access-Control-Allow-Origin": "'*'"
                            }
                        }
                    },
                    "requestParameters": {
                        "integration.request.path.mysfitId": "method.request.path.mysfitId"
                    },
                    "connectionType": "VPC_LINK",
                    "connectionId": "wg0305",
                    "httpMethod": "POST",
                    "security": [{
                        "MysfitsUserPoolAuthorizer": [

                        ]
                    }],
                    "type": "HTTP_PROXY",
                    "uri": "http://mysfits-nlb-52741b4979bb0b50.elb.us-east-2.amazonaws.com/mysfits/{mysfitId}/like",
                    "responses": {
                        "default": {
                            "statusCode": "200",
                            "responseParameters": {
                                "method.response.header.Access-Control-Allow-Headers": "'Content-Type,X-Amz-Date,Authorization,X-Api-Key'",
                                "method.response.header.Access-Control-Allow-Methods": "'*'",
                                "method.response.header.Access-Control-Allow-Origin": "'*'"
                            }
                        }
                    }
                }
            },
            "options": {
                "summary": "CORS support",
                "description": "Enable CORS by returning correct headers\n",
                "consumes": [
                    "application/json"
                ],
                "produces": [
                    "application/json"
                ],
                "tags": [
                    "CORS"
                ],
                "x-amazon-apigateway-integration": {
                    "type": "mock",
                    "requestTemplates": {
                        "application/json": "{\n  \"statusCode\" : 200\n}\n"
                    },
                    "responses": {
                        "default": {
                            "statusCode": "200",
                            "responseParameters": {
                                "method.response.header.Access-Control-Allow-Headers": "'Content-Type,X-Amz-Date,Authorization,X-Api-Key'",
                                "method.response.header.Access-Control-Allow-Methods": "'*'",
                                "method.response.header.Access-Control-Allow-Origin": "'*'"
                            },
                            "responseTemplates": {
                                "application/json": "{}\n"
                            }
                        }
                    }
                },
                "responses": {
                    "200": {
                        "description": "Default response for CORS method",
                        "headers": {
                            "Access-Control-Allow-Headers": {
                                "type": "string"
                            },
                            "Access-Control-Allow-Methods": {
                                "type": "string"
                            },
                            "Access-Control-Allow-Origin": {
                                "type": "string"
                            }
                        }
                    }
                }
            }
        }
    }
}

我收到错误:

An error occurred (BadRequestException) when calling the ImportRestApi operation: Errors found during import:
        Unable to put integration on 'GET' for resource at path '/': Invalid HTTP endpoint specified for URI

我哪里错了?哪个 URI 无效?如何添加更多错误捕获以查看遇到此异常的行和异常消息?

【问题讨论】:

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


    【解决方案1】:

    因为您的 swagger 文件格式不正确。它在验证时给出错误“重复的映射键”。我认为您已经两次定义了“响应”。

    【讨论】:

    • 你解决了吗
    【解决方案2】:

    我有同样的问题。很简单,'/'中的URI应该是http://mysfits-nlb-52741b4979bb0b50.elb.us-east-2.amazonaws.com

    【讨论】:

      猜你喜欢
      • 2017-11-26
      • 2019-07-09
      • 2018-02-16
      • 2022-12-10
      • 2019-10-03
      • 2019-08-19
      • 1970-01-01
      • 1970-01-01
      • 2020-07-04
      相关资源
      最近更新 更多