For an AWS SAM template, I used a CloudFormation condition like so:
AWSTemplateFormatVersion: '2010-09-09'
Transform: AWS::Serverless-2016-10-31
Description: Example
Parameters:
Environment:
Type: String
Description: Deployment environment
Default: prd
Conditions:
IsProd:
Fn::Equals:
- !Ref Environment
- prd
Resources:
ExampleScheduledFunction:
Type: AWS::Serverless::Function
Properties:
Events:
ScheduleEvent:
Type: ScheduleV2
Properties:
ScheduleExpression: "cron(0 3 ? * MON *)"
State:
Fn::If:
- IsProd
- ENABLED
- DISABLED
Reference: