How to inject values from a plugin into serverless.yml variables?

I want to create a Lambda function that uses an existing DynamoDB stream as the event source.
The DynamoDB table/stream is not currently setup using serverless or CloudFormation. It’s created using the SDK for legacy reasons.

One thought I had was to write a plugin that finds the stream’s ARN then somehow inject that into the serverless CloudFormation stack creation.

I don’t seem to be able to do this by creating a serverless variable which I then reference from the serverless.yml function’s stream config as the severless.yml file is processed before the plugin runs.

I’ve seen some plugins that manually manipulate the the compiled cloud formation stack, and another plugin that injects cloud formation parameters into the stack. Will dig into those options more, but wondering if there is a better way?

Another option would be just write this as a script before we run our serverless deploy and pass the value in as an option or env var, when calling sls deploy. But was hoping to take advantage of serverless plugins to make this more streamlined.

Just wondering if there are better options?

1 Like