“Uzyskaj dane z Python S3 Bucket” Kod odpowiedzi

Odczyt dane z S3 Bucket Python

# read data from s3 bucket python
s3 = boto3.resource('s3')
bucket = s3.Bucket('test-bucket')
for object in bucket.objects.all():
    key = object.key
    body = object.get()['Body'].read()
visualscrapper

Uzyskaj dane z Python S3 Bucket

Get data from s3 bucket python:

def s3_read(source, profile_name=None):
    """
    Read a file from an S3 source.

    Parameters
    ----------
    source : str
        Path starting with s3://, e.g. 's3://bucket-name/key/foo.bar'
    profile_name : str, optional
        AWS profile

    Returns
    -------
    content : bytes

    botocore.exceptions.NoCredentialsError
        Botocore is not able to find your credentials. Either specify
        profile_name or add the environment variables AWS_ACCESS_KEY_ID,
        AWS_SECRET_ACCESS_KEY and AWS_SESSION_TOKEN.
        See https://boto3.readthedocs.io/en/latest/guide/configuration.html
    """
    session = boto3.Session(profile_name=profile_name)
    s3 = session.client('s3')
    bucket_name, key = mpu.aws._s3_path_split(source)
    s3_object = s3.get_object(Bucket=bucket_name, Key=key)
    body = s3_object['Body']
    return body.read()
Breakable Badger

Odpowiedzi podobne do “Uzyskaj dane z Python S3 Bucket”

Pytania podobne do “Uzyskaj dane z Python S3 Bucket”

Więcej pokrewnych odpowiedzi na “Uzyskaj dane z Python S3 Bucket” w Python

Przeglądaj popularne odpowiedzi na kod według języka

Przeglądaj inne języki kodu