Disable Function Per Stage?


Some of our functions can’t be deployed to certain stages.
How can I disable the function based on stage?
Is there an expression capability in the yml?


1 Like

Hi Adam,

As far as I’m aware this functionality doesn’t exist.

I assume there are certain functions you don’t want deployed to production? What’s the use case? What problem are you trying to solve?

Can you separate the functions that can’t be deployed to certain stages into separate projects that are deployed separately?

+1 all the things @johncmckim said.

If your functions can’t be deployed to the same stage(s), they don’t belong in the same service.

This might actually be related to the issue I recently opened about our DynamoDB backup service.

When a DyanmoDB stream event is triggered, I don’t want all my Serverless stages to try to back up the same record.

My use case is we have develop, release and master stages.

The functions in question are maintenance jobs for our analytics. We don’t run analytics in the release stage and the develop stage doesn’t get enough data to warrant running the functions.

They are grouped with other functions that do get deployed. So u guess the answer is to seperate them into seperate projects

Having them deployed is no issue I guess by disabled I mean no triggers or in the case of develop different triggers to master would work

@AdamM I would still deploy those functions but optionally disable certain logic per stage. You could do that by injecting the stage as an environment variable. You can then check the variable and not invoke certain logic based on that.

I wouldn’t avoid triggering those lambdas, otherwise how do you know those triggers actually work? Just stub out what you need to and log that it was triggered. That said, if you’re only execute code in production, you run a real risk of having issues that only appear in production.

1 Like