メインコンテンツにスキップ
Adaptive Planning
最終更新: 2023-06-23
ai.awss3

ai.awss3

関数

方法
パラメータ
返品
説明
getFile(BucketName, key, region, awsAccess Key, AwsSecretkey)
バケット名: 文字列
キー: 文字列
region: 文字列
awsAccesskey: 文字列
awsSecretKey: String
AWS S3 バケットからファイルを取得します。
putFile(bucketName, key, region, awsAccessKey, AwsSecretKey)
バケット名: 文字列
キー: 文字列
doc:String
region: 文字列
awsAccesskey: 文字列
awsSecretKey: String
AWS S3 バケットにファイルを入力します。
listKeys(bucketName, region, awsAccessKey, awsSecretKey)
5000 キーを超えるバケットにはお勧めしません。
バケット名: 文字列
region: 文字列
awsAccesskey: 文字列
awsSecretKey: String
AWS S3 バケット内のキー (ファイル) を一覧表示します。
listObjects(request, region, awsAccessKey, awsSecretKey)
リクエスト オブジェクトのパラメータ
詳細については、Amazon S3 Request Docs を 参照してください。
バケット名: 文字列 (必須)。
ContingentToken: トークンのあるバケットでリストが継続されることを示します。前の応答で取得した "nextContinationToken"。
区切り文字: キーをグループ化するために使用される文字。Amazon S3 の階層的なキーのリスト化を参照してください。
コーディング: 回答で使用するエンコーディング方法。
取得: 各キーを持つリストの所有者に対して true に設定します。指定されていない場合、所有者はヌルになります。
max Keys: 応答内のキーの最大数。
Prefix: 指定した接頭辞で始まるキーに応答を制限します。
requestPlayer: String
startAfter: リストはこのキーの後に開始します。バケット内の任意のキーを使用します。継続トークンと同時に設定することはできません。
回答オブジェクトのパラメータ
詳細については、S3 Response Docs を 参照してください。
s3Objects: 検出されたオブジェクトのリスト。
keyCount: 検出されたオブジェクトの数。
isTruncated: 最初のリクエストに一致するキーが多数存在するかどうかを示します。リクエストで指定できます。AWS のデフォルト値は 1,000 です。
NextContinationToken: isTruncated が true の場合に送信され、バケット内のキーをさらにリストできることを示します。このnextContinationToken でリストを続行できます。
httpStatusCode:
名前:
prefix:
max Keys:
区切り文字:
commonPrefixes:
エンコーディング:
continuationToken:
startAfter:
AWS S3 バケット内のオブジェクトを一覧表示します。リクエスト内のパラメータを使用して、取得したキーを制限およびフィルタリングできます。
// Invoke this method using 'Test connection' in Actions pane function testConnection(context) { exampleGetFile(context); exampleListKeys(context); return true; } //Example for getFile function exampleGetFile(context) { var bucketName = 'xxx'; var key = 'newfile.xml'; var awsAccessKey = 'xxx'; var awsSecretKey = 'xxx'; var region = 'xxx'; var doc = ai.xml.createDocument(); var myFile=ai.awss3.getFile(bucketName, key, region, awsAccessKey, awsSecretKey); ai.log.logVerbose("File contents are",JSON.stringify(myFile)); } //Column,Heading,Names\n,2016-05-31T00:00:00,49570.89,4110_Product_Revenue_Grp_A,Sales - Canada\n,..... //Example for listkeys function exampleListKeys(context) { var bucketName = 'xxx'; var key = 'test.csv'; var awsAccessKey = 'xxx'; var awsSecretKey = 'xxx'; var region = 'xxx'; var myFile=ai.awss3.listKeys(bucketName, region, awsAccessKey, awsSecretKey); ai.log.logVerbose("Keys are",JSON.stringify(myFile)); return true; } //Keys are ["attribute-import-demo.csv","cloadertest.csv"] //Example for putFile function exportData(context) { var bucketName = 'xxx'; var key = 'newfile.xml'; var awsAccessKey = 'xxx'; var awsSecretKey = 'xxx'; var region = 'xxx'; var doc = ai.xml.createDocument(); var requestEl = ai.xml.createElement('request'); doc.setRootElement(requestEl); ai.awss3.putFile(bucketName, key, doc.toString(), region, awsAccessKey, awsSecretKey); //This will create the "newfile.xml" with a single line "<request />" }
listObjects を使用した例
この例では、オブジェクトをリクエストし、結果をページングする方法を示します。
//Navigate to Designer Settings tab and add 2 "text" parameters from the Settings pane. //Enter awsAccessKey and awsSecretKey in the Name fileds and provide your keys in the Value field function processFiles(context) { // Retrieve access and secret keys from settings const awsAccessKey = context.getDataSource().getSetting('awsAccessKey').getValue(); const awsSecretKey = context.getDataSource().getSetting('awsSecretKey').getValue(); const region = 'us-west-1' // Create the request for objects, at a minimum a bucket name is required const request = { BucketName: 'xxx', Prefix: 'mydata/', // Return keys from this directory }; // Push all the keys into an array const keyNames = []; let processing = true; while (processing) { var response = ai.awss3.listObjects(request, region, awsAccessKey, awsSecretKey); for (const entry of response.s3Objects) { // Here we have a single key that can be processed as desired keyNames.push(entry.key); } if (response.isTruncated) { // If the response did not include all remaining results, use the // nextContinuationToken from the response in the next request request.ContinuationToken = response.nextContinuationToken; } else { // If the response did include all remaining results, exit the loop ai.log.logInfo('Response indicated no further keys available'); processing = false; } } ai.log.logInfo("List of Objects:"+JSON.stringify(keyNames)); //List of Objects:["attribute-import-demo (7).csv","cloadertest.csv"] }
パラメータ リクエストの例
パラメータ
BucketName
, のみが必須です。
Prefix
はディレクトリです。
{ BucketName: 'ag-ccds-test', Prefix: 'samplenumber/', StartAfter: 'samplenumber/001_samplefile', MaxKeys: 3 }
サンプルの listObjects
この listOjbects 応答の例には、8 つのオブジェクトが含まれています。
{ "isTruncated": true, "s3Objects": [ { "eTag": "\"4c7507b8cf17a6650bcff6787ccd0915\"", "bucketName": "ag-ccds-test", "key": "archiveListing/archiveList_1575352592693.txt", "lastModified": "2019-12-03T15:56:34+10:00", "owner": null, "size": 1323, "storageClass": { "value": "STANDARD" } }, { "eTag": "\"b2addf641c43f17df4492524c834984c\"", "bucketName": "ag-ccds-test", "key": "archiveListing/archiveList_1575353843184.txt", "lastModified": "2019-12-03T16:17:24+10:00", "owner": null, "size": 1323, "storageClass": { "value": "STANDARD" } }, { "eTag": "\"b2addf641c43f17df4492524c834984c\"", "bucketName": "ag-ccds-test", "key": "archiveListing/archiveList_1575353844190.txt", "lastModified": "2019-12-03T16:17:25+10:00", "owner": null, "size": 1323, "storageClass": { "value": "STANDARD" } }, { "eTag": "\"b2addf641c43f17df4492524c834984c\"", "bucketName": "ag-ccds-test", "key": "archiveListing/archiveList_1575353845193.txt", "lastModified": "2019-12-03T16:17:26+10:00", "owner": null, "size": 1323, "storageClass": { "value": "STANDARD" } }, { "eTag": "\"b2addf641c43f17df4492524c834984c\"", "bucketName": "ag-ccds-test", "key": "archiveListing/archiveList_1575353846195.txt", "lastModified": "2019-12-03T16:17:27+10:00", "owner": null, "size": 1323, "storageClass": { "value": "STANDARD" } }, { "eTag": "\"b2addf641c43f17df4492524c834984c\"", "bucketName": "ag-ccds-test", "key": "archiveListing/archiveList_1575353847194.txt", "lastModified": "2019-12-03T16:17:28+10:00", "owner": null, "size": 1323, "storageClass": { "value": "STANDARD" } }, { "eTag": "\"b2addf641c43f17df4492524c834984c\"", "bucketName": "ag-ccds-test", "key": "archiveListing/archiveList_1575353848223.txt", "lastModified": "2019-12-03T16:17:29+10:00", "owner": null, "size": 1323, "storageClass": { "value": "STANDARD" } }, { "eTag": "\"b2addf641c43f17df4492524c834984c\"", "bucketName": "ag-ccds-test", "key": "archiveListing/archiveList_1575353849192.txt", "lastModified": "2019-12-03T16:17:30+10:00", "owner": null, "size": 1323, "storageClass": { "value": "STANDARD" } } ], "name": "ag-ccds-test", "prefix": "archiveListing/", "maxKeys": 8, "commonPrefixes": [], "delimiter": null, "encoding": null, "keyCount": 8, "continuationToken": null, "nextContinuationToken": "1Vut/ORdOSPdn8ZQdd8Z5nhNvlEfPkw0hkekFIDTVzk8Hn8jlttn/yIjkl67yK3RAUkPIoUHwDuiybia7Rx7YjVaRefLocnF4", "startAfter": null, "responseMetadata": { "requestId": "5ACCAA141D2F7D2B", "metadata": { "x-amz-id-2": "zlslMcRM+qj6SCKELuE2crlEzhc0eEFkpo5OC3Pzn9tMvtOYnaEkLoRQNj1m1SThPzI1lQ233Zo=" } }, "contentLength": -1, "httpStatusCode": 200 }