in apps/cloudwatch-dashboard/lambdas/list-schedulers/handler.py [0:0]
def create_synthetics(dashboard_name):
client = boto3.client('synthetics')
canary_name = 'scheduler-' + str(uuid.uuid4()).replace('-', '')[:11]
version = os.getenv('VERSION')
syn_source_bucket = os.getenv('SYN_SOURCE_BUCKET')
syn_source_prefix = 'cloudwatch-dashboard-source-code'
syn_source_code = f'{syn_source_prefix}/{version}/synthetics/canary-dashboard.zip'
syn_execution_role = os.getenv('SYN_EXECUTION_ROLE')
artifacts_s3_path = os.getenv('SYN_ARTIFACT_S3_PATH') + dashboard_name + '/'
stack_id = os.getenv('Stack')
snapshot_runs = os.getenv('SNAPSHOT_RUNS')
if snapshot_runs == 'Manual':
# Runs this canary only once, when it's started:
schedule_expression = 'rate(0 minute)'
elif snapshot_runs == 'Daily':
# Runs this canary every morning of the business week at 6am:
# Cron expression configuration reminder:
# Minutes Hours Day-of-Month Month Day-of-Week Year
schedule_expression = 'cron(0 6 ? * MON-FRI *)'
elif snapshot_runs == 'Weekly':
# Runs this canary every Monday morning at 6am:
schedule_expression = 'cron(0 6 ? * MON *)'
response = client.create_canary(
Name=canary_name,
Code={
'S3Bucket': syn_source_bucket,
'S3Key': syn_source_code,
'Handler': 'dashboard-snapshot.handler'
},
ArtifactS3Location=artifacts_s3_path,
ExecutionRoleArn=syn_execution_role,
Schedule={
'Expression': schedule_expression,
'DurationInSeconds': 0
},
RunConfig={
'TimeoutInSeconds': 180,
'MemoryInMB': 1024,
'ActiveTracing': False,
'EnvironmentVariables': {
'DASHBOARD': dashboard_name,
'STACK_ID': stack_id,
'VIEWPORT_HEIGHT': '700',
'DASHBOARD_TYPE': 'Scheduler'
}
},
SuccessRetentionPeriodInDays=31,
FailureRetentionPeriodInDays=31,
RuntimeVersion='syn-python-selenium-1.0'
)