def run_fargate()

in source/lambda/lambda_event_handler.py [0:0]


def run_fargate(props):
    ''' Check if there is any running fargate task, if not, run a new one '''
    cluster_name = props['cluster_name']
    family = props['family']
    subnets = props['subnets']
    sg = props['security_group']

    try:
        response = ecs.list_tasks(
            cluster=cluster_name,
            family=family,
            maxResults=1,
            desiredStatus='RUNNING',
        )
        print(response)

        # if no tasks is running, start a new task
        if not response['taskArns']:
            response = ecs.run_task(
                cluster=cluster_name,
                count=1,
                launchType='FARGATE',
                networkConfiguration={
                    'awsvpcConfiguration': {
                        'subnets': subnets,
                        'securityGroups': [
                            sg,
                        ],
                        'assignPublicIp': 'ENABLED'
                    }
                },
                taskDefinition=family
            )
    except Exception as e:
        print(e)