Carlos
Carlos

Reputation: 945

Deploying multiple AWS lambdas separately

I'm using Serverless Framework 1.32.0 with AWS Lambdas and Python 3.6. I would like to deploy multiple lambdas in a separate way, since at this moment I can only do deployments one by one for every lambda in my directory, which can be confusing with many lambdas in a short future.

This is my current project structure:

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

serverless.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

The problem is that, when I deploy it with serverless deploy --stage dev, it zips the full project and does not separate lambdas, so the actual Lambda in the AWS console shows as hello_cat but includes the full project structure instead of separating every lambda files in its own directory.

Is there a way to deploy separate lambdas in the same project with only one serverless.yml?

Thanks in advance.

Upvotes: 3

Views: 2218

Answers (2)

dp6000
dp6000

Reputation: 673

Besides including into serverless.yml, as proposed by @thomasmichaelwallace, the:

package:
    individually: true

Try changing the path of your handler function into hello_cat-functions.yml, from handler: service.handler to:

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

Upvotes: 0

thomasmichaelwallace
thomasmichaelwallace

Reputation: 8482

You'll need to configure Serverless to package individually

To do this add the following to your serverless.yaml:

package:
  individually: true

Upvotes: 2

Related Questions