script to download file from Amazon S3 bucket

后端 未结 5 1408
清歌不尽
清歌不尽 2021-02-08 00:06

Trying to write script to download file from Amazon S3 bucket.

Having trouble with the example on the cURL site. The script below produces:

The re

5条回答
  •  臣服心动
    2021-02-08 00:26

    As of August 2019 I found this to work. Has added region, and format of URL has changed.

    #!/bin/sh 
    outputFile="/PATH/TO/LOCALLY/SAVED/FILE"
    amzFile="BUCKETPATH/TO/FILE"
    region="YOUR-REGION"
    bucket="SOME-BUCKET"
    resource="/${bucket}/${amzFile}"
    contentType="binary/octet-stream"
    dateValue=`TZ=GMT date -R`
    # You can leave our "TZ=GMT" if your system is already GMT (but don't have to)
    stringToSign="GET\n\n${contentType}\n${dateValue}\n${resource}"
    s3Key="ACCESS_KEY_ID"
    s3Secret="SECRET_ACCESS_KEY"
    signature=`echo -en ${stringToSign} | openssl sha1 -hmac ${s3Secret} -binary | base64`
    curl -H "Host: s3-${region}.amazonaws.com" \
         -H "Date: ${dateValue}" \
         -H "Content-Type: ${contentType}" \
         -H "Authorization: AWS ${s3Key}:${signature}" \
         https://s3-${region}.amazonaws.com/${bucket}/${amzFile} -o $outputFile
    

提交回复
热议问题