amazon-web-servicesmechanicalturk

Is there any way or workaround to schedule Amazon Mechanical Turk HITs?


I need a specific HIT to run every Friday morning. Is there any way to do this or any workaround with an external platform (IFTTT, zapier both don't work) to do this? It seems to me like a very fundamental feature.


Solution

  • FWIW, I figured out how to use Zapier with MTurk. If you are on a paid plan you can leverage the AWS Lambda app to trigger some code that will create a HIT on MTurk. To do this you need an AWS account that's linked to your MTurk account. Once you have that you can create a Lambda function that contains the following code for creating a HIT on MTurk:

    import json
    import boto3
    
    def lambda_handler(event, context):
        print(event)
    
        ###################################
        # Step 1: Create a client
        ###################################
        endpoint = "https://mturk-requester.us-east-1.amazonaws.com"
        mturk = boto3.client(
        service_name='mturk',
        region_name='us-east-1',
        endpoint_url=endpoint)
    
        ###################################
        # Step 2: Define the task
        ###################################
        html = '''
            <**********************************
            My task HTML
            ***********************************>
        '''.format(event['<my parameter>'])
    
        question_xml = '''
        <HTMLQuestion xmlns="http://mechanicalturk.amazonaws.com/AWSMechanicalTurkDataSchemas/2011-11-11/HTMLQuestion.xsd">
        <HTMLContent><![CDATA[{}]]></HTMLContent>
        <FrameHeight>0</FrameHeight>
        </HTMLQuestion>'''.format(html)
    
        task_attributes = {
        'MaxAssignments': 3,
        'LifetimeInSeconds': 60 * 60 * 5, # Stay active for 5 hours
        'AssignmentDurationInSeconds': 60 * 10, # Workers have 10 minutes to respond
        'Reward': '0.03',
        'Title': '<Task title>',
        'Keywords': '<keywords>',
        'Description': '<Task description>'
        }
    
        ###################################
        # Step 3: Create the HIT
        ###################################
        response = mturk.create_hit(
        **task_attributes,
        Question=question_xml
        )
        hit_type_id = response['HIT']['HITTypeId']
        print('Created HIT {} in HITType {}'.format(response['HIT']['HITId'], hit_type_id))
    

    Note you'll need to give the role your Lambda is using access to MTurk. From there you can create an IAM user for Zapier to use when calling your Lambda and link it to your Zapier account. Now you can setup your Action to call that Lambda function with whatever parameters you want to pass in the event.

    If you want to get the results of the HIT back into your Zap it will be more complicated because Zapier isn't well suited to the asynchronous nature of MTurk HITs. I've put together a blog post on how to do this below: https://www.daveschultzconsulting.com/2019/07/18/using-mturk-with-zapier/