Warm tip: This article is reproduced from stackoverflow.com, please click
amazon-s3 amazon-web-services python-3.x amazon-sagemaker

how to set path of bucket in amazonsagemaker jupyter notebook?

发布于 2020-03-27 10:28:07

I'm new to the aws how to set path of my bucket and access file of that bucket?

Is there anything i need to change with prefix ?

import os
import boto3
import re
import copy
import time
from time import gmtime, strftime
from sagemaker import get_execution_role

role = get_execution_role()

region = boto3.Session().region_name

bucket='ltfs1' # Replace with your s3 bucket name
prefix = 'sagemaker/ltfs1' # Used as part of the path in the bucket where you store data
# bucket_path = 'https://s3-{}.amazonaws.com/{}'.format(region,bucket) # The URL to access the bucket

I'm using the above code but it's showing file not found error

Questioner
Scott
Viewed
93
ketcham 2019-07-03 23:14

If the file you are accessing is in the root directory of your s3 bucket, you can access the file like this:

import pandas as pd

bucket='ltfs1'
data_key = 'data.csv'
data_location = 's3://{}/{}'.format(bucket, data_key)
training_data = pd.read_csv(data_location)