주 컨텐츠로 이동
Adaptive Planning
최종 업데이트: 2023-06-23
ai.awss3

ai.awss3

함수

방법
매개변수
반품
설명
getFile(bucketName, key, region, awsAccessKey, AwsSecretKey)
bucketName: String
키: 문자열
지역: 문자열
awsAccesskey: 문자열
awsSecretKey: String
AWS S3 버킷에서 파일을 검색합니다.
putFile(bucketName, key, region, awsAccessKey, AwsSecretKey)
bucketName: String
키: 문자열
doc:String
지역: 문자열
awsAccesskey: 문자열
awsSecretKey: String
파일을 AWS S3 버킷에 저장합니다.
listKeys(bucketName, region, awsAccessKey, awsSecretKey)
키가 5,000개가 넘는 버킷에는 권장되지 않습니다.
bucketName: String
지역: 문자열
awsAccesskey: 문자열
awsSecretKey: String
AWS S3 버킷의 키(파일)를 나열합니다.
listObjects(request, region, awsAccessKey, awsSecretKey)
요청 오브젝트 매개변수
자세한 내용은Amazon S3 문서 요청을참조하십시오.
버킷명: 문자열(필수)
ContinuationToken: 토큰을 사용하여 이 버킷에서 목록이 계속됨을 나타냅니다. 이전 응답에서 가져온 nextContinuationToken입니다.
구분 기호: 키를 그룹화하는 데 사용되는 문자입니다. 계층적으로 Amazon S3 키 나열 문서를참조하십시오.
인코딩: 응답에 사용할 인코딩 방법입니다.
fetchOwner: 각 키와 함께 소유자를 나열하려면 true로 설정합니다. 지정하지 않으면 소유자가 null입니다.
maxKeys: 응답의 최대 키 수입니다.
접두어: 지정된 접두어로 시작하는 키로 응답을 제한합니다.
requestPlayer: 문자열
startAfter: 이 키 이후에 목록이 시작됩니다. 버킷의 키를 사용합니다. ContinuationToken과 동시에 설정할 수 없습니다.
응답 오브젝트 매개변수
자세한 내용은Amazon S3 응답 문서를참조하십시오.
s3Objects: 찾은 오브젝트의 목록입니다.
keyCount: 찾은 오브젝트 수입니다.
isTruncated: 초기 요청과 일치하는 키가 더 있는지 여부를 나타냅니다. 요청에서 지정할 수 있습니다. AWS의 기본값은 1,000입니다.
nextContinuationToken: isTruncated가 true일 때 전송되며, 버킷의 더 많은 키를 나열할 수 있음을 나타냅니다. 이 nextContinuationToken을 사용하여 목록을 계속할 수 있습니다.
httpStatusCode:
이름:
접두어:
maxKeys:
구분 기호:
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 }