
Emmanuel Corral Marco
PreguntaBuenas,
Alguien sabe como usar “with open”, para abrir archivos ubicados en S3 de AWS.
He probado con otras librerias como boto3, urllib3 ,requests. pero no me deja usando el típico enlace S3://bucket/archivo.yaml

Emmanuel Corral Marco
Muchas gracias!!, yo al final lo solucione usando una combinación de boto3 y yaml.
import yaml import boto3 bucket = "bucket_name" s3_client = boto3.client('s3') response = s3_client.get_object(Bucket=bucket, Key="key_name_on_s3") data = yaml.safe_load(response["Body"])
Al final en la variable data me cargo el archivo yaml sin problema, voy a probar tu aporte y gracias de nuevo!

Omar Daniel Centeno
Hola
He visto diferentes formas de acceder a la información que espero te ayuden. Utilizando smart open:
from smart_open import smart_open # stream lines from an S3 object for line in smart_open('s3://mybucket/mykey.txt', 'rb'): print(line.decode('utf8'))
Utilizando el context manager con smart open:
with smart_open('s3://mybucket/mykey.txt', 'rb') as s3_source: for line in s3_source: print(line.decode('utf8')) s3_source.seek(0) # seek to the beginning b1000 = s3_source.read(1000) # read 1000 bytes
Accediendo con boto3, pero sin readlines()
s3 = boto3.resource('s3') bucket = s3.Bucket('test-bucket') # Iterates through all the objects, doing the pagination for you. Each obj # is an ObjectSummary, so it doesn't contain the body. You'll need to call # get to get the whole body. for obj in bucket.objects.all(): key = obj.key body = obj.get()['Body'].read()