upload data to S3 with sagemaker

人走茶凉 提交于 2019-12-10 11:16:53

问题


I have a problem with SageMaker when I try to upload Data into S3 bucket . I get this error :


NameError                                 Traceback (most recent call last)
<ipython-input-26-d21b1cb0fcab> in <module>()
     19 download('http://data.mxnet.io/data/caltech-256/caltech-256-60-train.rec')
     20 
---> 21 upload_to_s3('train', 'caltech-256-60-train.rec')

<ipython-input-26-d21b1cb0fcab> in upload_to_s3(channel, file)
     13     data = open(file, "rb")
     14     key = channel + '/' + file
---> 15     s3.Bucket(bucket).put_object(Key=key, Body=data)
     16 
     17 

NameError: name 'bucket' is not defined

Here is the script:

import os
import urllib.request
import boto3

def download(url):
    filename = url.split("/")[-1]
    if not os.path.exists(filename):
        urllib.request.urlretrieve(url, filename)


def upload_to_s3(channel, file):
    s3 = boto3.resource('s3')
    data = open(file, "rb")
    key = channel + '/' + file
    s3.Bucket(bucket).put_object(Key=key, Body=data)


# caltech-256 download('http://data.mxnet.io/data/caltech-256/caltech-256-60-train.rec')

upload_to_s3('train', 'caltech-256-60-train.rec')

回答1:


It is exactly as the error say, the variable bucket is not defined. you might want to do something like

bucket = <name of already created bucket in s3>

before you call

s3.Bucket(bucket).put_object(Key=key, Body=data)


来源:https://stackoverflow.com/questions/49977679/upload-data-to-s3-with-sagemaker

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!