Example #1
0
def get_s3_content(s3_uri: str, s3_client: BaseClient = None):
    """
    Read an s3 URI

    :param s3_uri: a fully qualified S3 URI for the s3 object to read
    :param s3_client: an optional botocore.client.BaseClient for s3
    :return: the data from the s3 object
    """
    if s3_client is None:
        s3_client = s3_io_client()
    try:
        s3_uri = S3URI(s3_uri)
        LOGGER.info("Read s3-uri: %s", s3_uri.s3_uri)
        content_object = s3_client.get_object(Bucket=s3_uri.bucket,
                                              Key=s3_uri.key)
        file_content = content_object["Body"].read().decode("utf-8")
        return file_content
    except ClientError as err:
        LOGGER.error("Failed S3 PUT to: %s", s3_uri)
        LOGGER.error(err)
def get_data(bucket: str, key: str, s3_client: BaseClient) -> List[dict]:
    option = {"Bucket": bucket, "Key": key}
    resp = s3_client.get_object(**option)
    return json.load(resp["Body"])
Example #3
0
def get_image_bytes(bucket: str, key: str, s3_client: BaseClient) -> bytes:
    """
    S3から画像のbytesを取得する
    """
    resp = s3_client.get_object(Bucket=bucket, Key=key)
    return resp['Body'].read()