【问题标题】:Invalid HTTP endpoint specified for URI in Amazon ApiGateway在 Amazon ApiGateway 中为 URI 指定的 HTTP 终端节点无效
【发布时间】:2019-04-17 13:04:51
【问题描述】:

我正在尝试使用 cloudformation 模板为 API 网关使用 GET 方法创建资源 /user/devices,但它给了我以下错误

发生错误:ApiGatewayRootMethod - 为 URI 指定的 HTTP 端点无效(服务:AmazonApiGateway;状态代码:400;错误代码:BadRequestException;请求 ID:xxxxxxxxxx)

下面是我的cloudformation模板,

AWSTemplateFormatVersion: 2018-11-13
Description: test user

resources:
  Resources:

    UserDeviceApiGateway:
      Type: "AWS::ApiGateway::RestApi"
      Properties:
        Name: "test-user-info"
        Description: "Fetch the user"

    UserResource:
      Type: 'AWS::ApiGateway::Resource'
      Properties:
        ParentId:
          Fn::GetAtt: ["UserDeviceApiGateway","RootResourceId"]
        RestApiId:
          Ref: "UserDeviceApiGateway"
        PathPart: 'user'

    Resource:
      Type: 'AWS::ApiGateway::Resource'
      Properties:
        ParentId:
          Ref: "UserResource"
        RestApiId:
          Ref: "UserDeviceApiGateway"
        PathPart: 'devices'

    ApiGatewayRootMethod:
      Type: "AWS::ApiGateway::Method"
      Properties:
        AuthorizationType: "NONE"
        HttpMethod: "GET"
        Integration:
          IntegrationHttpMethod: "GET"
          Type: "HTTP"
          Uri: Sub
            - "arn:aws:apigateway:arn:aws:lambda:eu-west-1:lambda:path/2015-03-31/functions/arn:aws:lambda:eu-west-1:xxxxxxxx:function:user-device-lambda/invocations"
        ResourceId:
          Fn::GetAtt: ["UserDeviceApiGateway","RootResourceId"]
        RestApiId:
          Ref: "UserDeviceApiGateway"

    Deployment:
      DependsOn:
        - ApiGatewayRootMethod
      Type: 'AWS::ApiGateway::Deployment'
      Properties:
        RestApiId:
          Ref: "UserDeviceApiGateway"
        StageName: dev

【问题讨论】:

  • 你找到答案了吗?

标签: node.js amazon-web-services aws-api-gateway serverless-framework aws-serverless


【解决方案1】:

聚会有点晚了,但是……

您为 ApiGatewayRootMethod 指定 Type: "HTTP",但 HTTP 采用 API 端点 URL。您指定的 URI 格式由 Type: "AWS" 采用。

来自 AWS 文档:

用于集成的统一资源标识符 (URI)。

如果您为 Type 属性指定 HTTP,请指定 API 端点 URL。

如果您为 Type 属性指定 MOCK,请不要指定此属性。

如果您为 Type 属性指定 AWS,请指定遵循以下格式的 AWS 服务:arn:aws:apigateway:region:subdomain.service|service:path|action/service_api。例如,Lambda 函数 URI 遵循以下形式:arn:aws:apigateway:region:lambda:path/path。该路径的格式通常为 /2015-03-31/functions/LambdaFunctionARN/invocations。有关更多信息,请参阅 Amazon API Gateway REST API 参考中的集成资源的 uri 属性。

如果您为 Type 属性指定了 HTTP 或 AWS,则必须指定此属性。

https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-properties-apitgateway-method-integration.html

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2020-02-22
    • 2011-08-25
    • 1970-01-01
    • 2014-02-01
    • 2019-07-09
    • 2015-08-03
    • 1970-01-01
    • 2021-04-03
    相关资源
    最近更新 更多