Deploying DDB stream events to specific stage with v1

I have a v0.5 function that backs up DyanmoDB records to S3, and I’m in the process of migrating it to Serverless v1. But I’m confused with how to properly deploy this function…

In v0.5 my team could deploy the function to any stage, but the DynamoDB stream events were only deployed to our prod stage. But now that there’s no separate command to deploy the events, will the events get deployed to every stage along with the function?

I need to make sure that when DDB fires a stream event, only the function in the prod stage is triggered.

Is this currently possible with Serverless v1?

@adambiggs I assume you don’t share the DynamoDB table across stages? If not, you can have different instances of your lambda connected to each tables stream.

You can use the solution I describe here - Disable Function Per Stage?. But you run the same risks by only ever executing the code in production.

Thanks for the reply @johncmckim. That’s what I ended up doing.

I set up a SERVERLESS_STAGE variable using the serverless-plugin-write-env-vars plugin, and then simply return from the function without doing anything if the variable != 'prod'.

Seems like a bit of an inefficient solution… But it works.