Dans IAM, créez des utilisateurs par défaut, dev, prod. Attachez la stratégie AmazonS3FullAccess à dev pour autoriser l'accès à S3. Préparez bucket1, bucket2, bucket3 dans S3.
fichier d'identification
~/.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
Programme Python
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)
Programme Python
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