How to open a file downloaded from S3 by Zeppelin on a new Chrome tab?

时间:2019-05-31 11:57:47

标签: python amazon-web-services amazon-s3 boto3 apache-zeppelin

I'm trying to open a file from S3 using boto3 with Zepplin (running on AWS) machine but it keeps not working. My problem is that I need to open the file on a new tab from the computer that I'm using at the moment (not on Zepplin File System). Here is some code I did try:

Tried some webbrowser bib but it did not work.

import pyspark
import boto3
import botocore
import webbrowser
from boto3 import client

import urllib


BUCKET_NAME = "bucket_name" # replace with your bucket name
KEY = "bucket_name/path" # replace with your object key

s3 = boto3.resource('s3')

try:
   # conn = client('s3')  # again assumes boto.cfg setup, assume AWS S3
    #for key in conn.list_objects(Bucket=BUCKET_NAME)['Contents']:
    #    print( key['Key'])

    obj = s3.Object(BUCKET_NAME, KEY)
    fileToDownload  = obj.get()['Body'].read()
    print("did download")
    #TODO Open the File on a new tab
except botocore.exceptions.ClientError as e:
    if e.response['Error']['Code'] == "404":
        print("The object does not exist.")
    else:
        raise

0 个答案:

没有答案