2014-02-22 2 views
2

의 간단한 목록을 얻으려고합니다. 모두 공개 S3 버켓의 개체입니다.AWS S3 ListBucketResult 인증없이 페이지 매김?

listing with curl for upto 1000 results을 얻는 방법을 알고 있지만 결과를 페이지 매기기하는 방법을 이해하지 못해서 전체 목록을 얻으려고합니다. 제 생각에는 마커 단서입니다.

SDK/라이브러리 또는 인증을 사용하고 싶지 않습니다. 나는 이것을하기 위해 몇 줄의 쉘을 찾고있다.

+2

내가했습니다 지금 설치 내가 오류 얻을이 http://s3.dabase.com/ – hendry

답변

4
#!/bin/sh 

# setting max-keys higher than 1000 is not effective 
s3url=http://mr2011.s3-ap-southeast-1.amazonaws.com?max-keys=1000 
s3ns=http://s3.amazonaws.com/doc/2006-03-01/ 

i=0 
s3get=$s3url 

while :; do 
    curl -s $s3get > "listing$i.xml" 
    nextkey=$(xml sel -T -N "w=$s3ns" -t \ 
     --if '/w:ListBucketResult/w:IsTruncated="true"' \ 
     -v 'str:encode-uri(/w:ListBucketResult/w:Contents[last()]/w:Key, true())' \ 
     -b -n "listing$i.xml") 
    # -b -n adds a newline to the result unconditionally, 
    # this avoids the "no XPaths matched" message; $() drops newlines. 

    if [ -n "$nextkey" ] ; then 
     s3get=$s3url"&marker=$nextkey" 
     i=$((i+1)) 
    else 
     break 
    fi 
done 
+0

보여주는 서비스 : 인수에'오류 : 없음 -t 또는 --template 옵션 found'. 테스트 할 1000 개 이상의 오브젝트가있는'http : // mr2011.s3-ap-southeast-1.amazonaws.com'을 사용하십시오. – hendry

+0

아, 링크 된 페이지가 당신 것임을 알지 못했습니다. 또한 테스트를 위해 최대 키를 더 낮은 숫자로 설정할 수 있습니다 (1000 이상은 작동하지 않음). – npostavs

+0

'XPath가 일치하지 않습니다. 기본 네임 스페이스의 노드와 일치 시키려면 '_'을 접두어로 사용하십시오 (매뉴얼의 5.1 절 참조). 예를 들어,/node 대신/_ : node를 사용하십시오. – hendry