我正在处理每个堆栈最多只能使用200个资源的CloudFormation限制。似乎解决方案是将我的服务(serverless.yml文件)分成多个文件。我尝试过自动化方法和they don't work for me。所以,我正在研究手动的。但我不知道该怎么做。
这是我有的一个示例文件:
service: serverless-test
provider:
name: aws
runtime: nodejs12.x
endpointType: REGIONAL
plugins:
- serverless-aws-alias
functions:
authorizerFunc:
handler: code.authorizer
users:
handler: code.users
events:
- http:
path: /user
integration: lambda
authorizer: authorizerFunc
method: get
cors: true
request:
passThrough: WHEN_NO_TEMPLATES
template:
application/json: '{ "action": "list_users" }'
- http:
path: /user
integration: lambda
authorizer: authorizerFunc
method: post
cors: true
request:
passThrough: WHEN_NO_TEMPLATES
template:
application/json: '{ "action": "create_user", "payload": $input.body }'
posts:
handler: code.posts
events:
- http:
path: /post
integration: lambda
authorizer: authorizerFunc
method: get
cors: true
request:
passThrough: WHEN_NO_TEMPLATES
template:
application/json: '{ "action": "list_posts" }'
- http:
path: /post
integration: lambda
authorizer: authorizerFunc
method: post
cors: true
request:
passThrough: WHEN_NO_TEMPLATES
template:
application/json: '{ "action": "create_post", "payload": $input.body }'
有没有人能帮我把这个文件分成两份或三份?您可以随意以任何方式拆分它(只要生成的文件单独具有较少的资源)。只是JS代码应该保持不变。另外,请密切关注serverless-aws-alias
插件。这是我服务的关键部分。当然,目的是部署多个文件应该与部署单个文件相同。
发布于 2020-04-19 17:22:17
据我所知,您应该能够通过拆分网关来处理此问题。
我建议首先创建一个部署了共享部件、应用编程接口网关和授权程序的serverless.yml
service: api-gw
provider:
name: aws
runtime: nodejs12.x
stage: dev
region: eu-west-2
functions:
authorizerFunc:
handler: handler.handler
plugins:
- serverless-aws-alias
resources:
Resources:
MyApiGW:
Type: AWS::ApiGateway::RestApi
Properties:
Name: MyApiGW
Outputs:
apiGatewayRestApiId:
Value:
Ref: MyApiGW
Export:
Name: MyApiGateway-restApiId
apiGatewayRestApiRootResourceId:
Value:
Fn::GetAtt:
- MyApiGW
- RootResourceId
Export:
Name: MyApiGateway-rootResourceId
其余部分将根据资源数量进行拆分:
service: service-users
provider:
name: aws
runtime: nodejs12.x
region: eu-west-2
apiGateway:
restApiId:
'Fn::ImportValue': MyApiGateway-restApiId
restApiRootResourceId:
'Fn::ImportValue': MyApiGateway-rootResourceId
websocketApiId:
'Fn::ImportValue': MyApiGateway-websocketApiId
plugins:
- serverless-aws-alias
functions:
users:
handler: handler.handler
events:
- http:
path: /user
integration: lambda
authorizer:
arn: authorizerFuncARN
method: get
cors: true
request:
passThrough: WHEN_NO_TEMPLATES
template:
application/json: '{ "action": "list_users" }'
- http:
path: /user
integration: lambda
authorizer:
arn: authorizerFuncARN
method: post
cors: true
request:
passThrough: WHEN_NO_TEMPLATES
template:
application/json: '{ "action": "create_user", "payload": $input.body }'
您还应该考虑将您的授权器arn导出到以后可以在其他无服务器的yaml中重用的东西,比如ssm?
https://stackoverflow.com/questions/61292542
复制相似问题