首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >Serverless中微服务间的API网关共享

Serverless中微服务间的API网关共享
EN

Stack Overflow用户
提问于 2020-06-02 02:29:34
回答 1查看 285关注 0票数 0

我对Serverless还是个新手。我最近在Serverless上遇到了可怕的200资源限制问题,因此我试图分解我的服务,并在它们之间使用一个公共的API网关,但我一直得到Another resource with the same parent already has this name: assets。我使用公共api网关属性,因为我没有此服务的域。

这是我的主serverless.yml

代码语言:javascript
复制
    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文件

代码语言:javascript
复制
    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
EN

回答 1

Stack Overflow用户

发布于 2020-06-02 20:07:22

我意外地使用了从第二个服务函数i.e. assets/addmaintainence开始的相同路径,将其更改为maintainence/addmaintainence实现了此目的

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/62138579

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档