Hi There,
I know that the framework supports variables in serverless.yml
.
This is grate features, thank you very much.
But how to reference self variable from a list?
Here is example:
events:
- schedule:
rate: cron(0 0 1 * ? *)
input:
dateFormat: "YYYY-MM-DD-hh-mm-ss"
cronFormat: "0 0 1 * ? *"
As you can see I have a duplication (rate & input.cronFormat). I would like to avoid it and use something like:
cronFormat: ${../rate}
Is it possible?
Thank you in advance,
Mike
I’d think you can use the standard pattern for variables to accomplish this.
I tend to use this pattern - in my custom section I have something like:
custom:
cronrate: ${opt:cronrate, self:custom.cronrate_default} # Set the custom variable
cronrate_default: "0 0 1 * ? *" # Cron rate value
Then in your code you use the variable like:
events:
- schedule:
rate: cron(${self:custom.cronrate})
input:
dateFormat: "YYYY-MM-DD-hh-mm-ss"
cronFormat: "${self:custom.cronrate}"
Hi @roboweaver
Thank you for your answer.
Maybe I didn’t describe my problem correctly.
In my case I have list of more than dozen events. End for every event I need different values for rate
and crobFormat
. Like:
events:
- schedule:
rate: cron(0 0 1 * ? *)
input:
dateFormat: "YYYY-MM-DD-hh-mm-ss"
cronFormat: "0 0 1 * ? *"
- schedule:
rate: cron(0 0 2 * ? *)
input:
dateFormat: "YYYY-MM-DD-hh-mm-ss"
cronFormat: "0 0 2 * ? *"
- schedule:
rate: cron(0 0 3 * ? *)
input:
dateFormat: "YYYY-MM-DD-hh-mm-ss"
cronFormat: "0 0 3 * ? *"
...
Thank you,
Mike