def create_synthetics()

in apps/cloudwatch-dashboard/lambdas/list-models/handler.py [0:0]


def create_synthetics(dashboard_name):
    client = boto3.client('synthetics')
    
    canary_name = 'modeleval-' + 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')

    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': 'rate(0 minute)',
            'DurationInSeconds': 0
        },
        RunConfig={
            'TimeoutInSeconds': 180,
            'MemoryInMB': 1024,
            'ActiveTracing': False,
            'EnvironmentVariables': {
                'DASHBOARD': dashboard_name,
                'STACK_ID': stack_id,
                'VIEWPORT_HEIGHT': '1850',
                'DASHBOARD_TYPE': 'ModelEvaluation'
            }
        },
        SuccessRetentionPeriodInDays=31,
        FailureRetentionPeriodInDays=31,
        RuntimeVersion='syn-python-selenium-1.0'
    )
    
    status = 'CREATING'
    while status != 'READY':
        response = client.get_canary(Name=canary_name)
        status = response['Canary']['Status']['State']
        time.sleep(1)
        
    response = client.start_canary(Name=canary_name)