0

Been googling around and reading boto3 docs. Not sure why this is stumping me. Basically, I have an S3 bucket with a bucket policy that allows access via ARN. (I don't have key or ID)

I'm trying to write some sample code for my client to access via Python3/Boto3.

I was approaching it as:

import boto3

# Replace with ARN of your IAM role
arn="arn:aws:iam::123456789:role/example-role"

# Create an S3 client
s3 = boto3.client('s3', role_arn=arn)

# Get list of objects in the bucket
response = s3.list_objects(Bucket=arn)

# Print list of objects
for obj in response['Contents']:
    print(obj['Key'])

But I get the following error:

TypeError: Session.client() got an unexpected keyword argument 'role_arn'

I'm on the following boto3 version in a virtual env:

python3 -c "import boto3, sys; print(f'{sys.version} \nboto3: {boto3.__version__}')"
3.10.7 (main, Oct  3 2022, 18:38:27) [Clang 12.0.0 (clang-1200.0.32.29)]
boto3: 1.26.67

Any help is appreciated. Thanks.

mr-sk
  • 13,174
  • 11
  • 66
  • 101
  • Do you have a reference for being able to use `role_arn=arn`? I don't think it is supported by boto3. Instead, you need to call `AssumeRole()` and use the returned credentials, as shown in the linked Answer. – John Rotenstein Feb 09 '23 at 21:29

0 Answers0