【发布时间】: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