将 csv 写入 s3 存储桶不一致错误

时间:2021-06-30 08:03:06

标签: python amazon-web-services amazon-s3 amazon-sagemaker

<块引用>

未指定的位置约束与区域不兼容 此请求发送到的特定端点

我需要从 sagemaker 笔记本将大量 CSV 写入 s3 存储桶

我使用以下代码。

def create_user_block(algo
                  ,user
                  ,items
                  , pathTo
                  , popularity=None):

log('Creation of user block for {} started'.format(user))

recomendations = []
for item in items:
    recomendations.append(algo.predict(uid=user, iid=item))

    
recomendations = pd.DataFrame(recomendations)['iid est'.split()]
recomendations['est'] = recomendations.est.round()
recomendations = recomendations[ recomendations.est >=4]


if popularity is not None:
    popularity.columns = 'iid Popularity'.split()
    recomendations = recomendations.merge(right=popularity, how='left', on='iid')
    recomendations = recomendations.sort_values(by='est Popularity'.split(), ascending = False)

else:
    recomendations = recomendations.sort_values(by='est', ascending = False)

log('User block for {} returned'.format(user))

recomendations.to_csv( pathTo+'user_'+user+'.csv', index=False)

该函数从模型创建一个 csv 文件,然后将其写入特定位置。

到目前为止一切顺利

该函数围绕着第二个函数,该函数简单地递增并计算一些全局变量以跟踪我的进度

def create_user_block_progress(algo
                           , user
                           , items
                           , popularity
                           , pathTo =os.environ['UPCARS_RECOMMENDATION_LOCATION']):
global count, noUI, progress

try:
    create_user_block(algo=algo, user=user, items = items, pathTo=pathTo, popularity=popularity)

    count = count+1


    if progress < int(((count/noUI)*100)):
        progress = int(((count/noUI)*100))

        update_item(field = 'progress'
                , value = progress
                , tableName = os.environ['UPCARS_ACTIVE_TASK_TABLE']
                , key = os.environ['UPCARS_ACTIVE_TASK_KEY']
                , createdAt = os.environ['UPCARS_ACTIVE_TASK_CREATED_AT'])

except Exception as e:
    meta_log('FAILED to create user block for {} due to the following error: {}'.format(user, e), True)

然后我在多个线程上运行包装函数,如下所示:

 with concurrent.futures.ThreadPoolExecutor() as executor:
        threads = [executor.submit(create_user_block_progress
                                    , algo
                                    , u
                                    , items
                                    , itemPopularity) for u in users]

pathTo 是一个 S3 存储桶,直到昨天为止都没有问题。截至最近两天,我不断收到偶尔的错误。正如在此错误中,无论是否完全相同的用户都可能发生或不可能发生。有时会发生有时不会。有时它根本不会发生。有时它一直发生。

当它发生时,我收到以下错误:

<块引用>

未指定的位置约束与区域不兼容 此请求发送到的特定端点

到目前为止,我对问题所在感到困惑。如果有人可以帮助我,我将不胜感激。

实际上有时会出现该问题,我不知道为什么当我尝试将 csv 写入 s3 存储桶时。

给出错误的命令类似于:

recomendations.to_csv( 's3://local-recommendations/m1/knn/v8/user_123567.csv', index=False)

正是这个命令有时会出错,有时不会。不一致令人发狂

0 个答案:

没有答案
相关问题