簡體   English   中英

分別部署多個 AWS lambda

[英]Deploying multiple AWS lambdas separately

我將無服務器框架 1.32.0 與 AWS Lambdas 和 Python 3.6 一起使用。 我想以單獨的方式部署多個 lambda,因為此時我只能對目錄中的每個 lambda 進行一個一個的部署,這可能會在不久的將來與許多 lambda 混淆。

這是我目前的項目結構:

└── cat_service
    │   
    ├── hello_cat
    │   ├── hello_cat-functions.yml
    │   └── service.py
    │   
    ├── random_cat_fact
    │   ├── random_cat_fact-functions.yml
    │   └── service.py
    │   
    └── serverless.yml

無服務器.yml

service: cat-service 

provider:
  name: aws
  runtime: python3.6
  stage: dev
  stackName: cat-service
  deploymentBucket:
    name: test-cat-bucket
  role: arn:aws:iam::#{AWS::AccountId}:role/lambda-cat-role
  cfnRole: arn:aws:iam::#{AWS::AccountId}:role/cloudformation-cat-role

functions:
  - ${file(lambdas/hello_cat/hello_cat-functions.yml)}

stepFunctions:
  stateMachines:
    catStateMachine:
      definition:
        Comment: "Get cat hello"
        StartAt: hello_cat
        States:
          hello_cat:
            Type: Task
            Resource: "arn:aws:lambda:#{AWS::Region}:#{AWS::AccountId}:function:${self:service}-${opt:stage}-hello_cat"
            End: true

plugins:
  - serverless-step-functions
  - serverless-pseudo-parameters

hello_cat-functions.yml

msc_cat_facts:
  handler: service.handler
  name: ${self:service}-${opt:stage}-msc_cat_facts

問題是,當我使用serverless deploy --stage dev部署它時,它會serverless deploy --stage dev整個項目並且不分離 lambda,因此 AWS 控制台中的實際 Lambda 顯示為hello_cat但包括完整的項目結構而不是分離每個 lambda文件在其自己的目錄中。

有沒有辦法只有一個部署在同一個項目單獨lambda表達式的方式serverless.yml

提前致謝。

您需要將 Serverless 配置為單獨打包

為此,請將以下內容添加到您的serverless.yaml

package:
  individually: true

此外,包括成serverless.yml建議,由@thomasmichaelwallace的:

package:
    individually: true

嘗試將處理程序函數的路徑更改為hello_cat-functions.yml ,從handler: service.handler到:

msc_cat_facts:
   handler: hello_cat/service.handler
   name: ${self:service}-${opt:stage}-msc_cat_facts

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM