在Amazon ApiGateway中为URI指定了无效的HTTP端点

时间:2018-11-14 14:18:23

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

我正在尝试使用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

1 个答案:

答案 0 :(得分:0)

聚会晚了一点,但是...

您为Type: "HTTP"指定了ApiGatewayRootMethod,但是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参考中的Integration资源的uri属性。

     

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

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