【问题标题】:Sharing an API gateway between micro services in Serverless在 Serverless 中的微服务之间共享 API 网关
【发布时间】:2020-06-02 20:07:22
【问题描述】:

我对无服务器还很陌生。我最近在无服务器上遇到了可怕的 200 资源限制问题,因此我试图分解我的服务并在它们之间使用公共 API 网关,但我不断收到Another resource with the same parent already has this name: assets。我正在使用通用 api 网关属性,因为我没有此服务的域。

这是我的主要serverless.yml

    app: xxx
    org: xxx
    service: xxx
    provider:
      name: aws
      runtime: nodejs12.x
      region: xxx
functions: 
....
    resources:
      Outputs:

        ApiGatewayRestId:
          Value:
            Ref: ApiGatewayRestApi
          Export:
            Name: assetsapi-${opt:stage, self:provider.stage}-ApiGatewayRestId
        RootResourceId:
          Value:
            Fn::GetAtt:
              - ApiGatewayRestApi
              - RootResourceId
          Export:
            Name: assetsapi-${opt:stage, self:provider.stage}-RootResourceId
        IamRoleLambdaExecution:
          Value:
            Fn::GetAtt: IamRoleLambdaExecution.Arn
          Export:
            Name: assetsapi-${opt:stage, self:provider.stage}-IamRoleLambdaExecution
        ApiGatewayResourceMaintainence:
          Value:
            Ref: ApiGatewayResourceMaintainence
          Export:
            Name: assetsapi-${opt:stage, self:provider.stage}-ApiGatewayResourceMaintainence
    Resources:
        # Rest API
        ApiGatewayRestApi:
          Type: AWS::ApiGateway::RestApi
          Properties:
            Name: assetsapi
            Description: assets API Gateway

        # Rest API Paths
        ApiGatewayResourceMaintainence:
          Type: AWS::ApiGateway::Resource
          Properties:
            RestApiId: { Ref: 'ApiGatewayRestApi' }
            ParentId: { Fn::GetAtt: 'ApiGatewayRestApi.RootResourceId' }
            PathPart: maintain

这是位于路径 api/maintainence/serverless.yml 内的第二个服务的 serverless.yml 文件

    service: maintainencemanagementservice
    custom:
      stage: '${opt:stage, self:provider.stage}'
      region: ${opt:region, self:provider.region}
      prefix: ${self:service}-${self:custom.region}-${self:custom.stage}
      rootApiGatewayId: 'assets-api-${self:custom.region}-${self:custom.stage}-restApiId'
      rootApiGatewayResourceId: 'assets-api-${self:custom.region}-${self:custom.stage}-rootResourceId'
    provider:
      name: aws
      runtime: nodejs12.x
      stage: dev
      region: xxxx
      apiGateway:
        restApiId:
          Fn::ImportValue: assetsapi-${opt:stage, self:provider.stage}-ApiGatewayRestId
        restApiRootResourceId:
          Fn::ImportValue: assetsapi-${opt:stage, self:provider.stage}-RootResourceId
        restApiResources:
          /maintainence:
            Fn::ImportValue: assetsapi-${opt:stage, self:provider.stage}-ApiGatewayResourceMaintainence,
      role:
        Fn::ImportValue: assetsapi-${opt:stage, self:provider.stage}-IamRoleLambdaExecution

【问题讨论】:

    标签: amazon-web-services aws-lambda serverless


    【解决方案1】:

    我不小心使用了从第二个服务函数 i.e. assets/addmaintainence 开始的相同路径,将其更改为 maintainence/addmaintainence 成功了

    【讨论】:

      猜你喜欢
      • 2017-05-27
      • 2016-07-30
      • 2016-11-05
      • 1970-01-01
      • 2017-05-29
      • 2023-03-21
      • 2019-07-22
      • 2017-09-26
      • 1970-01-01
      相关资源
      最近更新 更多