How to use the MTurk function from aws-sdk

Find comprehensive JavaScript aws-sdk.MTurk code examples handpicked from public code repositorys.

aws-sdk.MTurk is a client object that allows you to interact with the Amazon Mechanical Turk API in order to manage tasks and payments for human intelligence tasks.

25
26
27
28
29
30
31
32
33
34
35
    Reward: '0.01',
    Title: 'This is a hit for 256 console testing',
    Question: extQ,
};


const m = new AWS.MTurk();
m.createHIT(request, (err, data) => {
    if (err !== null && err !== undefined) {
        console.log('An error has occurred:\n' + JSON.stringify(err, null, 2));
    } else {
fork icon0
star icon0
watch icon0

How does aws-sdk.MTurk work?

aws-sdk.MTurk works by providing a client object that allows you to interact with the Amazon Mechanical Turk API. The client object includes methods for managing tasks, such as creating and deleting tasks, and for managing payments, such as approving or rejecting completed tasks. To use the aws-sdk.MTurk client object, you first need to create an instance of the object using the MTurk constructor. You then call methods on the client object to interact with the API. For example, you could create a new HIT (Human Intelligence Task) using the createHIT method: javascript Copy code {{{{{{{ const AWS = require('aws-sdk'); const mturk = new AWS.MTurk(); mturk.createHIT({ Title: 'Answer a survey', Description: 'Answer a short survey about your favorite foods', Reward: '0.50', MaxAssignments: 10, Question: ' 1 What is your favorite food? ', AssignmentDurationInSeconds: 3600, LifetimeInSeconds: 86400, Keywords: 'survey, food, favorite', RequesterAnnotation: 'survey-001' }, (err, data) => { if (err) { console.error(err); } else { console.log(data); } }); In this example, we create a new instance of the MTurk client object, and then call the createHIT method on the client object to create a new HIT. The createHIT method takes an object containing various properties for the HIT, such as the title, description, and reward for the HIT. Once the HIT is created, the response from the API is logged to the console. Note that you must have valid AWS credentials in order to use the aws-sdk.MTurk client object.

Ai Example

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
const AWS = require("aws-sdk");

const mturk = new AWS.MTurk();

// Create a new HIT
mturk.createHIT(
  {
    Title: "Answer a survey",
    Description: "Answer a short survey about your favorite foods",
    Reward: "0.50",
    MaxAssignments: 10,
    Question: " 1 What is your favorite food? ",
    AssignmentDurationInSeconds: 3600,
    LifetimeInSeconds: 86400,
    Keywords: "survey, food, favorite",
    RequesterAnnotation: "survey-001",
  },
  (err, data) => {
    if (err) {
      console.error(err);
    } else {
      console.log(data);
      const hitId = data.HIT.HITId;

      // Retrieve information about the HIT
      mturk.getHIT(
        {
          HITId: hitId,
        },
        (err, data) => {
          if (err) {
            console.error(err);
          } else {
            console.log(data);
          }
        }
      );
    }
  }
);

In this example, we create a new instance of the MTurk client object, and then call the createHIT method on the client object to create a new HIT. The createHIT method takes an object containing various properties for the HIT, such as the title, description, and reward for the HIT. Once the HIT is created, the HITId property from the response is used to retrieve information about the HIT using the getHIT method. The getHIT method takes an object containing the HITId property and returns information about the HIT, including the HIT's status and the number of assignments completed for the HIT. Note that you must have valid AWS credentials in order to use the aws-sdk.MTurk client object, and you will also need to have a valid Mechanical Turk account set up.