使用資料存取服務 (DAS) 代理程式存取S3和S3相容存儲

外部應用程式和查詢引擎可以透過 DAS 代理程式存取由watsonx.data管理的S3和S3相容儲存。

資料存取服務 (DAS) 代理功能在 2.1.2 中完全移除,在 watsonx.data 中也不再可用。 您無法使用資料存取服務 (DAS) 代理功能來存取物件儲存 ( S3, ADLS 和 ABS)。

要存取S3和S3相容儲存:

  1. 從watsonx.data資訊視窗取得 DAS 端點。 點選 i 主頁上的圖示可開啟訊息視窗。

  2. 將Java程式碼中的S3端點替換為 DAS 端點。

    <DAS endpoint>/cas/v1/proxy
    
  3. 將存取密鑰替換為中的編碼值Java程式碼如下:

    base64{<crn>|Basic base64{ibmlhapikey_<user_id>:<IAM_APIKEY>}}
    

    為了得到Base64編碼字串,使用以下命令之一:

    printf "username:<apikey>" | base64
    
    echo -n "username:<apikey>" | base64
    

使用 DAS 的Java程式碼範例

        String bucketName = "bucket1";
        String keyName = "folder1/file1";
        # replace the target object store endpoint with the DAS proxy endpoint
        String endpoint = "<DAS endpoint get from About page>/cas/v1/proxy";
        /** Replace the Access Key with watsonx.data user name and API key following the below base64 encoded method.
        * For Cloud Pak for Data: base64{<instanceid>|ZenAPIkey base64{username:<apikey>}}
        * For IBM Cloud: base64{<crn>|Basic base64{ibmlhapikey_<user_id>:<IAM_APIKEY>}}
        * For AWS: base64{<crn>|Basic base64{ibmlhapikey_ServiceId-<service_id>:<APIKEY>}}
        */
        String accessKey = "encoded value";
        String secretKey = "any string";

        BasicAWSCredentials cos_cred = new BasicAWSCredentials(accessKey, secretKey);
        EndpointConfiguration cosEndPoint = new EndpointConfiguration(endpoint, "us-east");
        AmazonS3 s3Client = AmazonS3ClientBuilder.standard().withPathStyleAccessEnabled(true)
                .withCredentials(new AWSStaticCredentialsProvider(cos_cred))
                .withEndpointConfiguration(cosEndPoint).build();
        GetObject.GetObjectTest(s3Client, bucketName, keyName);

有關資訊S3 REST API 權限,請參閱 S3 REST API 權限