parameters: (bucket, s3_key_prefix, destination)
return_statement: return True
docstring: Downloads a list of files to an S3 bucket with a particular S3 key prefix to 'destination'
      :param bucket: The name of the S3 bucket
      :param s3_key_prefix: The key prefix to apply to each of the files
      :param destination the path to which to download the files
      :return False if not artifacts were found, True otherwise
docstring_summary: Downloads a list of files to an S3 bucket with a particular S3 key prefix to 'destination'
      :param bucket: The name of the S3 bucket
      :param s3_key_prefix: The key prefix to apply to each of the files
      :param destination the path to which to download the files
      :return False if not artifacts were found, True otherwise
docstring_tokens: Downloads a list of files to an S3 bucket with a particular S3 key prefix to destination : param bucket : The name of the S3 bucket : param s3_key_prefix : The key prefix to apply to each of the files : param destination the path to which to download the files : return False if not artifacts were found True otherwise
function: def try_s3_download(bucket, s3_key_prefix, destination) -> bool:
      """
      Downloads a list of files to an S3 bucket with a particular S3 key prefix to 'destination'
      :param bucket: The name of the S3 bucket
      :param s3_key_prefix: The key prefix to apply to each of the files
      :param destination the path to which to download the files
      :return False if not artifacts were found, True otherwise
      """
      response = s3.list_objects_v2(Bucket=bucket, Prefix=s3_key_prefix)
      if not response:
          raise RuntimeError('Error listing S3 objects')
  
      if response.get('KeyCount') is None:
          logger.debug('Invalid S3 list objects response format')
          logger.debug(response)
          raise RuntimeError('Invalid response format.')
  
      key_count = response.get('KeyCount')
      if key_count == 0:
          logger.debug('No artifacts found')
          return False
  
      if not response.get('Contents'):
          logger.debug('Invalid S3 list objects response format')
          logger.debug(response)
          raise RuntimeError('Invalid response format.')
  
      for obj in response.get('Contents'):
          key = obj['Key']
  
          # extract file path with any subdirectories and remove the leading file separator
          output_path = os.path.join(destination, key[len(s3_key_prefix):].lstrip(os.sep))
          os.makedirs(os.path.dirname(output_path), exist_ok=True)
          logger.info('Downloading {}'.format(output_path))
          logger.debug("Downloading s3://{}/{} to {}".format(bucket, key, output_path))
          with open(output_path, 'wb') as fp:
              s3.download_fileobj(Fileobj=fp, Key=key, Bucket=bucket)
  
      return True
function_tokens: def try_s3_download ( bucket , s3_key_prefix , destination ) -> bool : response = s3 . list_objects_v2 ( Bucket = bucket , Prefix = s3_key_prefix ) if not response : raise RuntimeError ( 'Error listing S3 objects' ) if response . get ( 'KeyCount' ) is None : logger . debug ( 'Invalid S3 list objects response format' ) logger . debug ( response ) raise RuntimeError ( 'Invalid response format.' ) key_count = response . get ( 'KeyCount' ) if key_count == 0 : logger . debug ( 'No artifacts found' ) return False if not response . get ( 'Contents' ) : logger . debug ( 'Invalid S3 list objects response format' ) logger . debug ( response ) raise RuntimeError ( 'Invalid response format.' ) for obj in response . get ( 'Contents' ) : key = obj [ 'Key' ] # extract file path with any subdirectories and remove the leading file separator output_path = os . path . join ( destination , key [ len ( s3_key_prefix ) : ] . lstrip ( os . sep ) ) os . makedirs ( os . path . dirname ( output_path ) , exist_ok = True ) logger . info ( 'Downloading {}' . format ( output_path ) ) logger . debug ( "Downloading s3://{}/{} to {}" . format ( bucket , key , output_path ) ) with open ( output_path , 'wb' ) as fp : s3 . download_fileobj ( Fileobj = fp , Key = key , Bucket = bucket ) return True