4

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

发生错误: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
4

1 回答 1

1

派对有点晚了,但是...

您指定Type: "HTTP"forApiGatewayRootMethod但 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

于 2019-10-05T18:10:51.647 回答