- Install the boto3 library which is the AWS SDK for Python:
- Create an AWS IAM user with MTurk permissions and obtain the access key ID and secret access key. You will need these to authenticate with the MTurk API.
- Go to the IAM console in your AWS account.
- Click on "Users" in the sidebar, and then click "Add user".
- Enter a username for the new IAM user (e.g. "mturk-api-user") and select "Programmatic access" as the access type. Click "Next: Permissions".
- On the next screen, select "Attach existing policies directly" and search for "AmazonMTurkFullAccess". Check the box next to this policy to select it. This policy provides full access to the MTurk API.
- Click "Next: Tags" to skip the optional tags screen.
- Click "Next: Review" to review your settings, and then click "Create user" to create the IAM user.
- On the final screen, you'll see the access key ID and secret access key for the IAM user. Click "Download .csv" to download the credentials as a CSV file, or click "Show" to view the keys directly.
- run the code (make sure to update with the access keys)
import csv
import boto3
# Replace the endpoint URL with the appropriate MTurk endpoint for your account (e.g. https://mturk-requester-sandbox.us-east-1.amazonaws.com for the sandbox environment)
client = boto3.client('mturk',
aws_access_key_id='your_access_key',
aws_secret_access_key='your_secret_key',
endpoint_url='https://mturk-requester.us-east-1.amazonaws.com')
with open('your_csv_file.csv', 'r') as csvfile:
reader = csv.DictReader(csvfile)
for row in reader:
worker_id = row['mturk id']
assignment_id = row['assignment id']
amount = str(row['payment amount']) # Convert the payment amount to a string
# Send the bonus payment
response = client.send_bonus(WorkerId=worker_id, AssignmentId=assignment_id, BonusAmount=amount, Reason='Thank you for your work!')
# Print the response from the MTurk API
print(response)