amazon-sagemaker-clip-search icon indicating copy to clipboard operation
amazon-sagemaker-clip-search copied to clipboard

get_image_from_item_id s3 permission issue?

Open twocoins-ca opened this issue 1 year ago • 0 comments

On the def get_image_from_item_id(item_id = "B0896LJNLH", return_image=True):

item_idx = dataset.query(f"item_id == '{item_id}'").index[0]
s3_path = dataset.iloc[item_idx].path
local_data_root = f'./data/images'
local_file_name = Path(s3_path).name

s3down.download(f'{s3_data_root}{s3_path}', local_data_root)

local_image_path = f"{local_data_root}/{local_file_name}"
if return_image:
    img = Image.open(local_image_path)
    return img, dataset.iloc[item_idx].item_name_in_en_us
else:
    return local_image_path, dataset.iloc[item_idx].item_name_in_en_us

image, item_name = get_image_from_item_id()

It seems s3://amazon-berkeley-objects/images/small/ has some request permission issues?

File /opt/conda/lib/python3.10/site-packages/sagemaker/s3.py:144, in S3Downloader.download(s3_uri, local_path, kms_key, sagemaker_session) 141 else: 142 extra_args = None --> 144 sagemaker_session.download_data( 145 path=local_path, bucket=bucket, key_prefix=key_prefix, extra_args=extra_args 146 )

File /opt/conda/lib/python3.10/site-packages/sagemaker/session.py:405, in Session.download_data(self, path, bucket, key_prefix, extra_args) 403 if next_token != "": 404 request_parameters.update({"ContinuationToken": next_token}) --> 405 response = s3.list_objects_v2(**request_parameters) 406 contents = response.get("Contents") 407 # For each object, save its key or directory.

File /opt/conda/lib/python3.10/site-packages/botocore/client.py:530, in ClientCreator._create_api_method.._api_call(self, *args, **kwargs) 526 raise TypeError( 527 f"{py_operation_name}() only accepts keyword arguments." 528 ) 529 # The "self" in this scope is referring to the BaseClient. --> 530 return self._make_api_call(operation_name, kwargs)

File /opt/conda/lib/python3.10/site-packages/botocore/client.py:964, in BaseClient._make_api_call(self, operation_name, api_params) 962 error_code = parsed_response.get("Error", {}).get("Code") 963 error_class = self.exceptions.from_code(error_code) --> 964 raise error_class(parsed_response, operation_name) 965 else: 966 return parsed_response

ClientError: An error occurred (AccessDenied) when calling the ListObjectsV2 operation: Access Denied

twocoins-ca avatar May 17 '23 23:05 twocoins-ca