awslabs / amazon-sagemaker-workshop

Amazon SageMaker workshops: Introduction, TensorFlow in SageMaker, and more
Apache License 2.0
381 stars 211 forks source link

ClientError when running data_distribution_types.ipynb #1

Closed pilhokim closed 6 years ago

pilhokim commented 6 years ago

In the notebook data_distribution_types.ipynb,

data = get_gdelt('1979.csv')
data

The above code causes the following error. FYI, bucket is corretly assigned :

---------------------------------------------------------------------------
ClientError                               Traceback (most recent call last)
<ipython-input-11-89da4708d75f> in <module>()
----> 1 data = get_gdelt('1979.csv')
      2 data

<ipython-input-10-f7e5f1e2ec53> in get_gdelt(filename)
      1 def get_gdelt(filename):
      2     s3 = boto3.resource('s3')
----> 3     s3.Bucket('gdelt-open-data').download_file('events/' + filename, '.gdelt.csv')
      4     df = pd.read_csv('.gdelt.csv', sep='\t')
      5     header = pd.read_csv('https://www.gdeltproject.org/data/lookups/CSV.header.historical.txt', sep='\t')

~/anaconda3/envs/python3/lib/python3.6/site-packages/boto3/s3/inject.py in bucket_download_file(self, Key, Filename, ExtraArgs, Callback, Config)
    166     return self.meta.client.download_file(
    167         Bucket=self.name, Key=Key, Filename=Filename,
--> 168         ExtraArgs=ExtraArgs, Callback=Callback, Config=Config)
    169 
    170 

~/anaconda3/envs/python3/lib/python3.6/site-packages/boto3/s3/inject.py in download_file(self, Bucket, Key, Filename, ExtraArgs, Callback, Config)
    128         return transfer.download_file(
    129             bucket=Bucket, key=Key, filename=Filename,
--> 130             extra_args=ExtraArgs, callback=Callback)
    131 
    132 

~/anaconda3/envs/python3/lib/python3.6/site-packages/boto3/s3/transfer.py in download_file(self, bucket, key, filename, extra_args, callback)
    305             bucket, key, filename, extra_args, subscribers)
    306         try:
--> 307             future.result()
    308         # This is for backwards compatibility where when retries are
    309         # exceeded we need to throw the same error from boto3 instead of

~/anaconda3/envs/python3/lib/python3.6/site-packages/s3transfer/futures.py in result(self)
     71             # however if a KeyboardInterrupt is raised we want want to exit
     72             # out of this and propogate the exception.
---> 73             return self._coordinator.result()
     74         except KeyboardInterrupt as e:
     75             self.cancel()

~/anaconda3/envs/python3/lib/python3.6/site-packages/s3transfer/futures.py in result(self)
    231         # final result.
    232         if self._exception:
--> 233             raise self._exception
    234         return self._result
    235 

~/anaconda3/envs/python3/lib/python3.6/site-packages/s3transfer/tasks.py in _main(self, transfer_future, **kwargs)
    253             # Call the submit method to start submitting tasks to execute the
    254             # transfer.
--> 255             self._submit(transfer_future=transfer_future, **kwargs)
    256         except BaseException as e:
    257             # If there was an exception raised during the submission of task

~/anaconda3/envs/python3/lib/python3.6/site-packages/s3transfer/download.py in _submit(self, client, config, osutil, request_executor, io_executor, transfer_future, bandwidth_limiter)
    351                 Bucket=transfer_future.meta.call_args.bucket,
    352                 Key=transfer_future.meta.call_args.key,
--> 353                 **transfer_future.meta.call_args.extra_args
    354             )
    355             transfer_future.meta.provide_transfer_size(

~/anaconda3/envs/python3/lib/python3.6/site-packages/botocore/client.py in _api_call(self, *args, **kwargs)
    315                     "%s() only accepts keyword arguments." % py_operation_name)
    316             # The "self" in this scope is referring to the BaseClient.
--> 317             return self._make_api_call(operation_name, kwargs)
    318 
    319         _api_call.__name__ = str(py_operation_name)

~/anaconda3/envs/python3/lib/python3.6/site-packages/botocore/client.py in _make_api_call(self, operation_name, api_params)
    613             error_code = parsed_response.get("Error", {}).get("Code")
    614             error_class = self.exceptions.from_code(error_code)
--> 615             raise error_class(parsed_response, operation_name)
    616         else:
    617             return parsed_response

ClientError: An error occurred (403) when calling the HeadObject operation: Forbidden
rabowskyb commented 6 years ago

This likely is caused by a permissions problem related to the IAM role assigned to your notebook instance. Try to create a new notebook per https://github.com/awslabs/amazon-sagemaker-workshop/tree/master/NotebookCreation, and re-run the notebook. Or you can insert permissions to the following S3 bucket in the notebook instance role: gdelt-open-data.