events:
- schedule: cron(0 02 * * ? *) # Timezone: UTC
I want to set a reoccurring event but only in Production environment. Is that possible to configure int eh Serverless.yaml?
events:
- schedule: cron(0 02 * * ? *) # Timezone: UTC
I want to set a reoccurring event but only in Production environment. Is that possible to configure int eh Serverless.yaml?
You can take a look on the serverless-plugin-ifelse
custom:
myStage: ${opt:stage, self:provider.stage}
serverlessIfElse:
# Deploy schedule only in production env
- If: '"${self:custom.myStage}" != "production"'
Exclude:
- functions.yourfunction.events.0.schedule
Thanks, however managed to figure it out as:
custom:
stage: "${opt:stage, self:provider.stage}"
prod:
schedule: cron(0 02 * * ? *) # Timezone: UTC; Only run schedule in prod
dev:
schedule:
test:
schedule:
qa:
schedule:
And then for the Function:
events:
- schedule: ${self:custom.${self:custom.stage}.schedule}
When I try to take this strategy, I’m getting a warning (which will soon be an error in a new version)
`A valid service attribute to satisfy the declaration 'self:custom.dev.myVariableName' could not be found.`
because I have that empty, as you showed above. How did you get around that?
I’m having the same issue as @mattcaruso, but now it fails to build/deploy with
- Cannot resolve variable at "functions.my-function.events.0.schedule": Value not found at "self" source
any idea what to do?
My usecase: Using serverless to deploy a lambda, I have a function with a cloudWatch cron event. I don’t want to just disable for dev stage, I want to avoid creating the event at all when deploying to dev, only creating it when the function is deployed to prod