无法将请求编组到 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 (将#修改为@)