我用的是云格式和aws。在构建/部署应用程序时,是否有任何方法来计算所创建的资源的数量?例如,我有一个遵循无服务器架构的REST项目,它在Resources元素下只有193个函数。但这实际上产生了583个资源。我还知道这一点,因为它达到了aws堆栈资源限制,AWS显示了一条错误消息。
因此,我想知道是否有一种方法,我们可以知道真正的资源正在创建的数量。
下面是我制作的样本模板。
template.yaml
AWSTemplateFormatVersion: '2010-09-09'
Transform: AWS::Serverless-2016-10-31
Description: >
aws-restapi
Sample SAM Template for aws-restapi
# More info about Globals: https://github.com/awslabs/serverless-application-model/blob/master/docs/globals.rst
Globals:
Function:
Timeout: 5
VpcConfig:
SecurityGroupIds:
- sg-041f2xxxd921e8e
SubnetIds:
- subnet-03xxxb2d
- subnet-c4dxxxcb
Resources:
GetAllAccountingTypesFunction:
Type: AWS::Serverless::Function # More info about Function Resource: https://github.com/awslabs/serverless-application-model/blob/master/versions/2016-10-31.md#awsserverlessfunction
Properties:
CodeUri: aws-restapi/
Handler: source/accounting-types/accountingtypes-getall.getallaccountingtypes
Runtime: nodejs14.x
Events:
GetAllAccountingTypesAPIEvent:
Type: Api # More info about API Event Source: https://github.com/awslabs/serverless-application-model/blob/master/versions/2016-10-31.md#api
Properties:
Path: /accountingtypes/getall
Method: get
RestApiId:
Ref: ApiGatewayApi
GetAccountingTypeByIDFunction:
Type: AWS::Serverless::Function # More info about Function Resource: https://github.com/awslabs/serverless-application-model/blob/master/versions/2016-10-31.md#awsserverlessfunction
Properties:
CodeUri: aws-restapi/
Handler: source/accounting-types/accountingtypes-byid.getbyid
Runtime: nodejs14.x
Events:
GetAllAccountingTypesAPIEvent:
Type: Api # More info about API Event Source: https://github.com/awslabs/serverless-application-model/blob/master/versions/2016-10-31.md#api
Properties:
Path: /accountingtypes/getbyid
Method: get
RestApiId:
Ref: ApiGatewayApi
LambdaRole:
Type: 'AWS::IAM::Role'
Properties:
AssumeRolePolicyDocument:
Version: "2012-10-17"
Statement:
- Effect: Allow
Principal:
Service:
- lambda.amazonaws.com
Action:
- 'sts:AssumeRole'
Path: /
ManagedPolicyArns:
- arn:aws:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole
Policies:
- PolicyName: root
PolicyDocument:
Version: "2012-10-17"
Statement:
- Effect: Allow
Action:
- ec2:DescribeNetworkInterfaces
- ec2:CreateNetworkInterface
- ec2:DeleteNetworkInterface
- ec2:DescribeInstances
- ec2:AttachNetworkInterface
Resource: '*'
Outputs:
HelloWorldApi:
Description: "API Gateway endpoint URL for Prod stage for functions"
Value: !Sub "https://${ServerlessRestApi}.execute-api.${AWS::Region}.amazonaws.com/Prod/"发布于 2021-08-30 19:25:25
您可以使用sam通过sam validate --debug --template yourtempatefile.yaml转换模板,转换后的模板与其他调试消息一起输出到stderr。这个巴什·欧内莱纳为我计算资源。
$ sam validate --debug --template mytemplate.yaml 2>&1 | egrep '^ Properties:' | wc -l发布于 2021-08-30 10:33:45
据我所知,可能对您有所帮助的是这个Serverless无函数引用,,它告诉您在未指定某些属性时将隐式地生成哪些资源。
考虑到这一点,您可以计算实际创建的资源数量。
https://stackoverflow.com/questions/68982543
复制相似问题