Listar Bucket en AWS usando credenciales dinámicas
How To Specify Credentials When Connecting To AWS S3 Using Boto3?
import boto3
import botocore.session
def list_buckets():
"""
Use the AWS SDK for Python (Boto3) to create an Amazon Simple Storage Service
(Amazon S3) resource and list the buckets in your account.
This example uses the default settings specified in your shared credentials
and config files.
"""
s3_resource = boto3.resource(
's3',
aws_access_key_id='IOEURT84POIU520PRU02974',
aws_secret_access_key='gsjd48dufgRTTA3ou4/c11OQIU9+',
aws_session_token='Ba0FwoGZXIiohafsdhfaS/R/fqoih45ads4f5adfasdfaf5a==',
region_name='us-east-1',
)
# https://blog.knoldus.com/how-to-specify-credentials-when-connecting-to-aws-services-using-boto3/
session = botocore.session.get_session()
print(session.get_credentials().access_key)
print(session.get_credentials().secret_key)
print(session.get_credentials().token)
print("hola, Amazon S3! Lista de buckets:")
for bucket in s3_resource.buckets.all():
print(f"\t{bucket.name}")
if __name__ == '__main__':
list_buckets()
Comentarios