【问题标题】:upload data to S3 with sagemaker使用 sagemaker 将数据上传到 S3
【发布时间】:2018-12-07 06:53:27
【问题描述】:

当我尝试将数据上传到 S3 存储桶时,我遇到了 SageMaker 问题。我收到此错误:


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

这是脚本:

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')

【问题讨论】:

    标签: amazon-s3 amazon-sagemaker


    【解决方案1】:

    正如错误所说,变量bucket 未定义。 你可能想做一些类似

    的事情
    bucket = <name of already created bucket in s3>
    

    打电话之前

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

    【讨论】:

    • key 到底是什么?在文档上它说Object key for which the PUT action was initiated. 但不确定这意味着什么,您想将数据上传到(Body)的完整s3路径吗?
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2018-06-24
    • 2019-04-08
    • 1970-01-01
    • 2018-09-07
    • 2012-12-09
    • 2022-11-09
    • 1970-01-01
    相关资源
    最近更新 更多