微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

无法将请求编组到 JSON:在授予 api 网关权限以使用无服务器模板调用 lambda 时,restapi_id 不能为空

如何解决无法将请求编组到 JSON:在授予 api 网关权限以使用无服务器模板调用 lambda 时,restapi_id 不能为空

我使用无服务器模板创建 lambda 和 api 网关,并使用 lambda 权限资源提供调用 lambda 函数的 api 网关权限。但出现以下错误。我在 lambda 权限资源中正确地给出了 restapi_id,但仍然低于错误。能否请您提供一些解决问题的建议

错误:列出 api 网关关系时发生错误:无法将请求编组到 JSON:无法将请求编组到 JSON:restapi_id 不能为空

请找到 serverless.template。


AWstemplateFormatVersion:'2010-09-09'

转换:AWS::Serverless-2016-10-31

描述:一个使用 ASP.NET Core 框架运行的 AWS 无服务器应用程序 在亚马逊 Lambda 中。

参数:

帐号:

  Default: "$AccountId"

  Type: String
  

条件:{}

资源:

AspNetCoreFunction:

Type: AWS::Serverless::Function

Properties:

  Handler: <Handler>

  Runtime: dotnetcore3.1

  CodeUri: ''

  MemorySize: 256   

  Timeout: 30

  Role: "$Function_Role"

  Policies:
  

Lambda 权限:

Type: "AWS::Lambda::Permission"

Properties:

    Action: "lambda:InvokeFunction"

    FunctionName: !GetAtt AspNetCoreFunction.Arn

    Principal: "apigateway.amazonaws.com"

    SourceArn: !Sub "arn:aws:execute-api:${AWS::Region}:${AWS::AccountId}:${ApiTest}/*/*/swagger/*"

LambdaPermission2:

Type: "AWS::Lambda::Permission"

Properties:

    Action: "lambda:InvokeFunction"

    FunctionName: !GetAtt AspNetCoreFunction.Arn

    Principal: "apigateway.amazonaws.com"

    SourceArn: !Sub "arn:aws:execute-api:${AWS::Region}:${AWS::AccountId}:${ApiTest}/*/*/api/*"

API 测试:

Type: AWS::ApiGateway::RestApi

Properties:

  Name: Gateway-Api-Test

  ApiKeySourceType: HEADER

  EndpointConfiguration:

    Types:

    - REGIONAL

SwaggerResource:

Type: AWS::ApiGateway::Resource

Properties:

  RestApiId: !Ref ApiTest

  PathPart: swagger

  ParentId: !GetAtt ApiTest.RootResourceId

API 资源:

Type: AWS::ApiGateway::Resource

Properties:

  RestApiId: !Ref ApiTest

  PathPart: api

  ParentId: !GetAtt ApiTest.RootResourceId

SwaggerProxyResource:

Type: AWS::ApiGateway::Resource

Properties:

  RestApiId: !Ref ApiTest

  PathPart: "{proxy+}"

  ParentId: !Ref SwaggerResource

ApiProxyResource:

Type: AWS::ApiGateway::Resource

Properties:

  RestApiId: !Ref ApiTest

  PathPart: "{proxy+}"

  ParentId: !Ref ApiResource

API 方法

Type: AWS::ApiGateway::Method

Properties:

  RestApiId: !Ref ApiTest

  ResourceId: !Ref ApiProxyResource

  HttpMethod: "ANY"

  AuthorizationType: "NONE"


  ApiKeyrequired: false

  RequestParameters: 

      "method.request.path.proxy": true

  Integration:

    CacheKeyParameters: 

      - "method.request.path.proxy"

    CacheNamespace: !Ref ApiProxyResource


    IntegrationHttpMethod: POST

    TimeoutInMillis: 29000

    Type: AWS_PROXY

    Uri: !Sub arn:aws:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/arn:aws:lambda:${AWS::Region}:${AWS::AccountId}:function:${AspNetCoreFunction.Arn}/invocations

Swagger 方法

Type: AWS::ApiGateway::Method

Properties:

  RestApiId: !Ref ApiTest

  ResourceId: !Ref SwaggerProxyResource

  HttpMethod: "ANY"

  AuthorizationType: "NONE"

  ApiKeyrequired: false

  RequestParameters: 

      "method.request.path.proxy": true

  Integration:

    CacheKeyParameters: 

      - "method.request.path.proxy"

    CacheNamespace: !Ref SwaggerProxyResource


    IntegrationHttpMethod: POST

    TimeoutInMillis: 29000

    Type: AWS_PROXY

    Uri: !Sub arn:aws:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/${AspNetCoreFunction.Arn}/invocations

       

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。