How to serverless deploy without erasing the existing functions on Lambda?

if I have function_1, function_2 in my serverless.yml, like the following:
handler: handler.get_near_bars_lambda
handler: handler.get_facebook_event_data_lambda

And there are function_3, function_4 on aws lambda, different from function_1, function_2:

If I do serverless deploy, then function_3 and function_4 would be erased from lambda, and only function_1 and function_2 exist on aws lambda.

how should I config serverless so when I do serverless deploy the existing functions on aws lambda doesn’t get erased? I don’t have access to function_3 and function_4 in the above example because I am collaborating with someone else on the same aws lambda account.

Thank you in advance!

As far as I know, your two options are:

  1. Put all of the functions into a single serverless.yml file. Then you can use the -f option to deploy individual functions as you and your collaborator work on separate functions. You will have to deploy all of them at once the first time. For example:

Add all of your functions to a single serverless.yml file, then do sls deploy. Thereafter, to update individual functions, you can use the command sls deploy -f <function name> such as sls deploy -f function_1

  1. Split the functions in to separate serverless.yml files.

If it were me, I would use option 1. Depending on your use case, that might not be ideal. I tend to group my serverless functions by their use. For example, for an api, I would put all of the functions relating to one api into a single serverless file, all functions relating to a cognito sign up flow into one, and so on and so forth.

1 Like

Thank you so much for your reply. Does splitting the functions into separate severless.yml files prevent functions from erasing each other when deployed separately? If that’s the case then why my collaborator and I are erasing each other’s functions when we do serverless deploy considering we are using different serverless.yml files?

Maybe I misunderstood your situation.

It sounds like you two might have the same project name for your service.

Is the service part of your serverless.yml file the same for the both of you? If so, then that is your issue. Just change the service name, and serverless will not view them as pertaining to the same project, which would explain your experience.

1 Like

I see. We do have the same service name. That explains everything. Thank you so much for your help

Normally I deal with this approach.

name format:  ${self:service}-${self:custom.stage}-<some_unique_id_for example_your_name>

with that, you never have name conflict issue with others in the same aws account.