简体   繁体   English

拆分 serverless.yml 文件

[英]Split serverless.yml file

How would I split this serverless.yml file into two .yml files?我如何将这个 serverless.yml 文件拆分为两个 .yml 文件?

I hit the cloudFormation template validation error... " Number of resources, 202, is greater than the maximum allowed, 200"我遇到了 cloudFormation 模板验证错误...“资源数量,202,大于允许的最大值,200”

Ive been stuck on this for 5 days now and cant go any further with my application until I fix this issue.我已经被困在这个问题上 5 天了,在我解决这个问题之前无法继续我的应用程序。

How could I split up these services into different YML files with a main YML file?如何使用主 YML 文件将这些服务拆分为不同的 YML 文件?

Serverless.yml无服务器.yml

service: p-app-api

# Create an optimized package for our functions
package:
  individually: true

plugins:
  - serverless-bundle # Package our functions with Webpack
  - serverless-offline
  - serverless-dotenv-plugin

provider:
  name: aws
  runtime: nodejs10.x
  stage: dev
  region: us-east-2
  environment:
    stripeSecretKey: ${env:STRIPE_SECRET_KEY}
  # 'iamRoleStatements' defines the permission policy for the Lambda function.
  # In this case Lambda functions are granted with permissions to access DynamoDB.
  iamRoleStatements:
    - Effect: Allow
      Action:
        - dynamodb:DescribeTable
        - dynamodb:Query
        - dynamodb:Scan
        - dynamodb:GetItem
        - dynamodb:PutItem
        - dynamodb:UpdateItem
        - dynamodb:DeleteItem
      Resource: "arn:aws:dynamodb:us-east-2:433684495079:table/data"
    - Effect: Allow
      Action:
        - dynamodb:Query
        - dynamodb:Scan
      Resource: "arn:aws:dynamodb:us-east-2:433684495079:table/data/index/zipCode-packageSelected-index"
    - Effect: Allow
      Action:
        - dynamodb:Query
        - dynamodb:Scan
      Resource: "arn:aws:dynamodb:us-east-2:433684495079:table/data/index/jobId-index"
    - Effect: Allow
      Action:
        - dynamodb:DescribeTable
        - dynamodb:Query
        - dynamodb:Scan
        - dynamodb:GetItem
        - dynamodb:PutItem
        - dynamodb:UpdateItem
        - dynamodb:DeleteItem
      Resource: "arn:aws:dynamodb:us-east-2:433684495079:table/Service"
    - Effect: Allow
      Action:
        - dynamodb:Query
        - dynamodb:Scan
      Resource: "arn:aws:dynamodb:us-east-2:433684495079:table/Service/index/index"
    - Effect: Allow
      Action:
        - s3:*
      Resource: "arn:aws:s3:::service/public/*"
    - Effect: Allow
      Action:
        - dynamodb:DescribeTable
        - dynamodb:Query
        - dynamodb:Scan
        - dynamodb:GetItem
        - dynamodb:PutItem
        - dynamodb:UpdateItem
        - dynamodb:DeleteItem
      Resource: "arn:aws:dynamodb:us-east-2:433684495079:table/Service"
    - Effect: Allow
      Action:
        - dynamodb:Query
        - dynamodb:Scan
      Resource: "arn:aws:dynamodb:us-east-2:433684495079:table/data/index/packageSelected"

functions:
  # Defines an HTTP API endpoint that calls the main function in create.js
  # - path: url path is /notes
  # - method: POST request
  # - cors: enabled CORS (Cross-Origin Resource Sharing) for browser cross
  #     domain api call
  # - authorizer: authenticate using the AWS IAM role
  create:
    handler: create.main
    events:
      - http:
          path: data
          method: post
          cors: true
          authorizer: aws_iam
          arn: aws:cognito-idp:us-east-2:433684495079:userpool/us-east-2_Q0sUvw4Qy
  get:
    # Defines an HTTP API endpoint that calls the main function in get.js
    # - path: url path is /notes/{id}
    # - method: GET request
    handler: get.main
    events:
      - http:
          path: data/{id}
          method: get
          cors: true
          authorizer: aws_iam
          arn: aws:cognito-idp:us-east-2:433684495079:userpool/us-east-2_Q0sUvw4Qy
  list:
    # Defines an HTTP API endpoint that calls the main function in list.js
    # - path: url path is /notes
    # - method: GET request
    handler: list.main
    events:
      - http:
          path: data
          method: get
          cors: true
          authorizer: aws_iam
          arn: aws:cognito-idp:us-east-2:433684495079:userpool/us-east-2_Q0sUvw4Qy
  update:
    # Defines an HTTP API endpoint that calls the main function in update.js
    # - path: url path is /notes/{id}
    # - method: PUT request
    handler: update.main
    events:
      - http:
          path: data/{id}
          method: put
          cors: true
          authorizer: aws_iam
          arn: aws:cognito-idp:us-east-2:433684495079:userpool/us-east-2_Q0sUvw4Qy
  delete:
    # Defines an HTTP API endpoint that calls the main function in delete.js
    # - path: url path is /notes/{id}
    # - method: DELETE request
    handler: delete.main
    events:
      - http:
          path: data/{id}
          method: delete
          cors: true
          authorizer: aws_iam
          arn: aws:cognito-idp:us-east-2:433684495079:userpool/us-east-2_Q0sUvw4Qy
  createCustomer:
    # Defines an HTTP API endpoint that calls the main function in billing.js
    # - path: url path is /billing
    # - method: POST request
    handler: createCustomer.main
    events:
      - http:
          path: createCustomer
          method: post
          cors: true
          authorizer:
          arn: aws:cognito-idp:us-east-2:433684495079:userpool/us-east-2_Q0sUvw4Qy
  updateCustomer:
    # Defines an HTTP API endpoint that calls the main function in billing.js
    # - path: url path is /billing
    # - method: POST request
    handler: updateCustomer.main
    events:
      - http:
          path: updateCustomer
          method: post
          cors: true
          authorizer: aws_iam
          arn: aws:cognito-idp:us-east-2:433684495079:userpool/us-east-2_Q0sUvw4Qy
  listCustomerCard:
    # Defines an HTTP API endpoint that calls the main function in billing.js
    # - path: url path is /billing
    # - method: POST request
    handler: listCustomerCard.main
    events:
      - http:
          path: listCustomerCard/{id}
          method: get
          cors: true
          authorizer: aws_iam
          arn: aws:cognito-idp:us-east-2:433684495079:userpool/us-east-2_Q0sUvw4Qy
  deleteCard:
    # Defines an HTTP API endpoint that calls the main function in billing.js
    # - path: url path is /billing
    # - method: POST request
    handler: DeleteCard.main
    events:
      - http:
          path: deleteCard/{id}/{card}
          method: delete
          cors: true
          authorizer: aws_iam
          arn: aws:cognito-idp:us-east-2:433684495079:userpool/us-east-2_Q0sUvw4Qy
  getCustomerInfo:
    # Defines an HTTP API endpoint that calls the main function in billing.js
    # - path: url path is /billing
    # - method: POST request
    handler: getCustomerInfo.main
    events:
      - http:
          path: getCustomerInfo/{id}
          method: get
          cors: true
          authorizer: aws_iam
          arn: aws:cognito-idp:us-east-2:433684495079:userpool/us-east-2_Q0sUvw4Qy
  updateCustomerCard:
    # Defines an HTTP API endpoint that calls the main function in billing.js
    # - path: url path is /billing
    # - method: POST request
    handler: updateCustomerCard.main
    events:
      - http:
          path: updateCustomerCard/{id}
          method: post
          cors: true
          authorizer: aws_iam
          arn: aws:cognito-idp:us-east-2:433684495079:userpool/us-east-2_Q0sUvw4Qy
  createInvoice:
    # Defines an HTTP API endpoint that calls the main function in billing.js
    # - path: url path is /billing
    # - method: POST request
    handler: createInvoice.main
    events:
      - http:
          path: createInvoice
          method: post
          cors: true
          authorizer: aws_iam
          arn: aws:cognito-idp:us-east-2:433684495079:userpool/us-east-2_Q0sUvw4Qy
  deleteInvoice:
    # Defines an HTTP API endpoint that calls the main function in billing.js
    # - path: url path is /billing
    # - method: POST request
    handler: deleteInvoice.main
    events:
      - http:
          path: deleteInvoice/{id}
          method: delete
          cors: true
          authorizer: aws_iam
          arn: aws:cognito-idp:us-east-2:433684495079:userpool/us-east-2_Q0sUvw4Qy
  listInvoices:
    # Defines an HTTP API endpoint that calls the main function in billing.js
    # - path: url path is /billing
    # - method: POST request
    handler: listInvoices.main
    events:
      - http:
          path: listInvoices/{id}
          method: get
          cors: true
          authorizer: aws_iam
          arn: aws:cognito-idp:us-east-2:433684495079:userpool/us-east-2_Q0sUvw4Qy
  ListNewJobs:
    # Defines an HTTP API endpoint that calls the main function in billing.js
    # - path: url path is /billing
    # - method: POST request
    handler: ListNewJobs.main
    events:
      - http:
          path: data/ListNewJobs
          method: get
          cors: true
          authorizer: aws_iam
          arn: aws:cognito-idp:us-east-2:433684495079:userpool/us-east-2_Q0sUvw4Qy
  jobIndex:
    # Defines an HTTP API endpoint that calls the main function in billing.js
    # - path: url path is /billing
    # - method: POST request
    handler: jobIndex.main
    events:
      - http:
          path: data/jobIndex
          method: get
          cors: true
          authorizer: aws_iam
          arn: aws:cognito-idp:us-east-2:433684495079:userpool/us-east-2_Q0sUvw4Qy
  updateJobStatus:
    # Defines an HTTP API endpoint that calls the main function in billing.js
    # - path: url path is /billing
    # - method: POST request
    handler: updateJobStatus.main
    events:
      - http:
          path: data/jobStatus
          method: put
          cors: true
          authorizer: aws_iam
          arn: aws:cognito-idp:us-east-2:433684495079:userpool/us-east-2_Q0sUvw4Qy
  createNewJob:
    # Defines an HTTP API endpoint that calls the main function in billing.js
    # - path: url path is /billing
    # - method: POST request
    handler: createNewJob.main
    events:
      - http:
          path: ServiceJobs/createNewJob
          method: post
          cors: true
          authorizer: aws_iam
          arn: aws:cognito-idp:us-east-2:433684495079:userpool/us-east-2_Q0sUvw4Qy
  listMyNewJobs:
    # Defines an HTTP API endpoint that calls the main function in billing.js
    # - path: url path is /billing
    # - method: POST request
    handler: listMyNewJobs.main
    events:
      - http:
          path: ServiceJobs/listMyNewJobs
          method: get
          cors: true
          authorizer: aws_iam
          arn: aws:cognito-idp:us-east-2:433684495079:userpool/us-east-2_Q0sUvw4Qy
  DeleteMyNewJob:
    # Defines an HTTP API endpoint that calls the main function in billing.js
    # - path: url path is /billing
    # - method: POST request
    handler: DeleteMyNewJob.main
    events:
      - http:
          path: ServiceJobs/DeleteMyNewJob/{id}
          method: delete
          cors: true
          authorizer: aws_iam
          arn: aws:cognito-idp:us-east-2:433684495079:userpool/us-east-2_Q0sUvw4Qy
  UpdateServiceJobList:
    # Defines an HTTP API endpoint that calls the main function in update.js
    # - path: url path is /notes/{id}
    # - method: PUT request
    handler: UpdateServiceJobList.main
    events:
      - http:
          path: ServicesJobs/Update
          method: put
          cors: true
          authorizer: aws_iam
          arn: aws:cognito-idp:us-east-2:433684495079:userpool/us-east-2_Q0sUvw4Qy
  ServiceIndex:
    # Defines an HTTP API endpoint that calls the main function in billing.js
    # - path: url path is /billing
    # - method: POST request
    handler: ServiceIndex.main
    events:
      - http:
          path: ServiceJobs/ServiceIndex
          method: get
          cors: true
          authorizer: aws_iam
          arn: aws:cognito-idp:us-east-2:433684495079:userpool/us-east-2_Q0sUvw4Qy
  UpdateMyJob:
    # Defines an HTTP API endpoint that calls the main function in update.js
    # - path: url path is /notes/{id}
    # - method: PUT request
    handler: UpdateMyJob.main
    events:
      - http:
          path: ServiceJobs/UpdateMyJob
          method: put
          cors: true
          authorizer: aws_iam
          arn: aws:cognito-idp:us-east-2:433684495079:userpool/us-east-2_Q0sUvw4Qy
  PayInvoiceStripe:
    # Defines an HTTP API endpoint that calls the main function in billing.js
    # - path: url path is /billing
    # - method: POST request
    handler: PayInvoiceStripe.main
    events:
      - http:
          path: stripe/PayInvoice
          method: post
          cors: true
          authorizer: aws_iam
          arn: aws:cognito-idp:us-east-2:433684495079:userpool/us-east-2_Q0sUvw4Qy
  StripeNewContractorAccount:
    # Defines an HTTP API endpoint that calls the main function in billing.js
    # - path: url path is /billing
    # - method: POST request
    handler: StripeNewContractorAccount.main
    events:
      - http:
          path: stripe/NewContractorAccount
          method: post
          cors: true
          authorizer:
          arn: aws:cognito-idp:us-east-2:433684495079:userpool/us-east-2_Q0sUvw4Qy
  serviceInfoPut:
    # Defines an HTTP API endpoint that calls the main function in billing.js
    # - path: url path is /billing
    # - method: POST request
    handler: serviceInfoPut.main
    events:
      - http:
          path: serviceInfo/post
          method: post
          cors: true
          authorizer:
          arn: aws:cognito-idp:us-east-2:433684495079:userpool/us-east-2_Q0sUvw4Qy
  ListJobsForEdit:
    # Defines an HTTP API endpoint that calls the main function in billing.js
    # - path: url path is /billing
    # - method: POST request
    handler: ListJobsForEdit.main
    events:
      - http:
          path: data/index/packageSelected
          method: get
          cors: true
          authorizer: aws_iam
          arn: aws:cognito-idp:us-east-2:433684495079:userpool/us-east-2_Q0sUvw4Qy
# Create our resources with separate CloudFormation templates
resources:
  # API Gateway Errors
  - ${file(resources/api-gateway-errors.yml)}

I've had some good success using the serverless-plugin-split-stacks plugin.我使用serverless-plugin-split-stacks插件取得了一些不错的成功。

You can split your stacks by a few methods , but I'd imagine for your situation, you'd want to split per Lambda您可以通过几种方法拆分堆栈,但我想针对您的情况,您希望按Lambda拆分

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 cloudFormation 模板验证错误:如何拆分 serverless.yml 文件 - cloudFormation Template Validation Error: how to split serverless.yml file 如何将我的 serverless.yml 文件拆分为多个文件? - How can I split up my serverless.yml file into multiple files? 如何将条件放入 serverless.yml 文件中? - How can I put condition in serverless.yml file? 从jenkinsfile引用Serverless.yml文件中的环境变量 - Referencing Environment Variable in Serverless.yml File from jenkinsfile 如何在 serverless.yml 文件中获取 AccountId 作为变量? - How do I get the AccountId as a variable in a serverless.yml file? 如何在 serverless.yml 文件中引用 lambda 名称? - How can I reference lambda name in serverless.yml file? 是否可以使用Serverless 1.0.0-beta.1.1在“ serverless.yml”文件中设置请求授权? - Is it possible to set request authorization in 'serverless.yml' file with Serverless 1.0.0-beta.1.1? 获取无服务器框架在我的serverless.yml文件中创建的API网关资源的ARN - Get the ARN for the API gateway resource that the serverless framework creates within my serverless.yml file 如何在无服务器框架的“serverless.yml”文件中获取 URL 端点详细信息作为变量? - How to get URL endpoint detail as variable in Serverless Framework's `serverless.yml` file? 如何在serverless.yml中添加存储桶权限 - How to add bucket permission in serverless.yml
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM