JN_*_*bie 5 amazon-web-services node.js 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
Run Code Online (Sandbox Code Playgroud)
小智 3
聚会有点晚了,但是……
您可以指定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/incalls 的形式。有关更多信息,请参阅 Amazon API Gateway REST API Reference 中集成资源的 uri 属性。
如果您为 Type 属性指定了 HTTP 或 AWS,则必须指定此属性。
| 归档时间: |
|
| 查看次数: |
13365 次 |
| 最近记录: |