Boto3 Help Needed

I’m just getting started with boto3 and AWS. I found this article and tried the sample code. I don’t know if the sample code is wrong or if I need to be looking at something else. The bottom line is that the ‘for’ loop outputs nothing and I do not get any errors. Apparently ‘s3.buckets.all()’ returns nothing. Is there a better, more accurate tutorial for getting started with boto3? TIA.

import boto3
s3 = boto3.resource('s3')
for bucket in s3.buckets.all():

I know nothing about the boto3 library but I think it would be interesting to know how did you configure the credentials file: Quickstart — Boto3 Docs 1.24.42 documentation

Does the AWS CLI have a way how to test the connection and credentials? I would suggest running some kind of such a test.

Yes, the credentials file is correct.

You can check your credentials with

import boto3

Did you set up any S3 buckets? Check the output of

import boto3

Thanks for the reply. I don’t know what I’m supposed to see but the first returned this:

<botocore.credentials.Credentials object at 0x000001FA55B50340>

The 2nd returned this:

{‘ResponseMetadata’: {‘RequestId’: ‘BSYBFYKP2YB1FF0R’, ‘HostId’: ‘DkMXF2NIi2spxByxNN+g2BFfmRQ8NXR3RaoRWymV4wYcRLBdWjdj/E9e4QRryUV3q/KqxLBtFZA=’, ‘HTTPStatusCode’: 200, ‘HTTPHeaders’: {‘x-amz-id-2’: ‘DkMXF2NIi2spxByxNN+g2BFfmRQ8NXR3RaoRWymV4wYcRLBdWjdj/E9e4QRryUV3q/KqxLBtFZA=’, ‘x-amz-request-id’: ‘BSYBFYKP2YB1FF0R’, ‘date’: ‘Mon, 01 Aug 2022 13:56:56 GMT’, ‘content-type’: ‘application/xml’, ‘transfer-encoding’: ‘chunked’, ‘server’: ‘AmazonS3’}, ‘RetryAttempts’: 0}, ‘Buckets’: , ‘Owner’: {‘DisplayName’: ‘dap1’, ‘ID’: ‘afff17fba9ce9025fc3e955b63cf7831fd1ec41ddb3337287627ab367ea63099’}}

I did not set up any buckets knowingly. I thought buckets already existed which is why the tutorial started off with that code.

The first result is expected: it means you have credentials configured correctly.

The second result says you have no buckets in your AWS account.

Yes, you’ll need S3 buckets set up to have something to list. You can create one for no cost using boto3’s S3 client: docs. I would recommend disabling ACLs by setting ObjectOwnership="BucketOwnerEnforced" (using IAM instead)

Thanks for the reply again. I think I now understand the problem. My mturk and AWS accounts are not linked. I can find instructions on how to link an existing nmturk account to a new AWS account and how to link an existing AWS account to a new mturk account. For some reason there is nothing on how to link an existing AWS account to and existing mturk account.

I think I figured out how to link existing accounts but I don’t know how to tell if it worked. I get the same output using the credentials given after I supposedly linked the accounts.

I have no familiarity with mturk or AWS Single Sign On sorry.

The credentials result is specifically for authentication with AWS, not other services