Пример #1
0
def _aws_get_data(key, bucket, client: boto3_session.client = None) -> bytes:
    if not client:
        session = boto3_session()
        client = session.client("s3")

    response = client.get_object(Bucket=bucket, Key=key)
    return response["Body"].read()
Пример #2
0
def s3_get_object(bucket, key, client: boto3_session.client = None) -> bytes:
    """GetObject from S3."""
    if not client:
        session = boto3_session()
        client = session.client("s3")

    response = client.get_object(Bucket=bucket, Key=key)
    return response["Body"].read()
Пример #3
0
def _aws_get_data(key, bucket, client: boto3_session.client = None) -> bytes:
    if not client:
        session = boto3_session()
        client = session.client("s3")
    try:
        response = client.get_object(Bucket=bucket, Key=key)
    except ClientError as e:
        status_code = e.response["ResponseMetadata"]["HTTPStatusCode"]
        exc = _HTTP_EXCEPTIONS.get(status_code, MosaicError)
        raise exc(e.response["Error"]["Message"]) from e

    return response["Body"].read()
Пример #4
0
def aws_get_object(
    bucket: str,
    key: str,
    request_pays: bool = False,
    client: boto3_session.client = None,
) -> bytes:
    """AWS s3 get object content."""
    if not client:
        session = boto3_session()
        client = session.client("s3")

    params = {"Bucket": bucket, "Key": key}
    if request_pays:
        params["RequestPayer"] = "requester"
    response = client.get_object(**params)
    return response["Body"].read()
Пример #5
0
def aws_get_object(
    bucket: str,
    key: str,
    request_pays: bool = False,
    client: boto3_session.client = None,
) -> bytes:
    """AWS s3 get object content."""
    if not client:
        session = boto3_session()
        endpoint_url = os.environ.get("AWS_S3_ENDPOINT", None)
        client = session.client("s3", endpoint_url=endpoint_url)

    params = {"Bucket": bucket, "Key": key}
    if request_pays or os.environ.get("AWS_REQUEST_PAYER",
                                      "").lower() == "requester":
        params["RequestPayer"] = "requester"

    response = client.get_object(**params)
    return response["Body"].read()