In IAM, create default, dev, prod users. Attach the AmazonS3FullAccess policy to dev to allow access to S3. Prepare bucket1, bucket2, bucket3 in S3.
credentials file
~/.aws/credentials
or C:\Users\USER_NAME\.aws\credentials
[default]
aws_access_key_id = DEFAULT_ID
aws_secret_access_key = SECRET_KEY1
[dev]
aws_access_key_id = DEV_ID
aws_secret_access_key = SECRET_KEY2
[prod]
aws_access_key_id = PROD_ID
aws_secret_access_key = SECRET_KEY3
Python program
import boto3.session
dev_sess = boto3.session.Session(profile_name='dev')
s3 = dev_sess.resource('s3')
for bucket in s3.buckets.all():
print(bucket.name)
Python program
import boto3.session
dev_sess = boto3.session.Session(
aws_access_key_id='DEV_ID',
aws_secret_access_key='SECRET_KEY2')
s3 = dev_sess.resource('s3')
for bucket in s3.buckets.all():
print(bucket.name)
bucket1
bucket2
bucket3
ClientError: An error occurred (AccessDenied) when calling the ListBuckets operation: Access Denied
ProfileNotFound: The config profile (foo) could not be found