首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >我们如何计算由CloudFormation模板生成的资源数量?

我们如何计算由CloudFormation模板生成的资源数量?
EN

Stack Overflow用户
提问于 2021-08-30 10:26:30
回答 2查看 147关注 0票数 0

我用的是云格式和aws。在构建/部署应用程序时,是否有任何方法来计算所创建的资源的数量?例如,我有一个遵循无服务器架构的REST项目,它在Resources元素下只有193个函数。但这实际上产生了583个资源。我还知道这一点,因为它达到了aws堆栈资源限制,AWS显示了一条错误消息。

因此,我想知道是否有一种方法,我们可以知道真正的资源正在创建的数量。

下面是我制作的样本模板。

template.yaml

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

回答 2

Stack Overflow用户

发布于 2021-08-30 19:25:25

您可以使用sam通过sam validate --debug --template yourtempatefile.yaml转换模板,转换后的模板与其他调试消息一起输出到stderr。这个巴什·欧内莱纳为我计算资源。

代码语言:javascript
复制
$ sam validate --debug --template mytemplate.yaml 2>&1 | egrep '^    Properties:'  | wc -l
票数 1
EN

Stack Overflow用户

发布于 2021-08-30 10:33:45

据我所知,可能对您有所帮助的是这个Serverless无函数引用,,它告诉您在未指定某些属性时将隐式地生成哪些资源。

考虑到这一点,您可以计算实际创建的资源数量。

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

https://stackoverflow.com/questions/68982543

复制
相关文章

相似问题

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