script to download file from Amazon S3 bucket

后端 未结 5 1410
清歌不尽
清歌不尽 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:34

    #!/bin/sh
    # This works for cross region
    outputFile="/PATH/TO/FILE"
    awsFile="BUCKETPATH/TO/FILE"
    bucket="SOME-BUCKET"
    resource="/${bucket}/${awsFile}"
    contentType="application/x-compressed-tar"
    # Change the content type as desired
    dateValue=`TZ=GMT date -R`
    #Use dateValue=`date -R` if your TZ is already GMT
    stringToSign="GET\n\n${contentType}\n${dateValue}\n${resource}"
    s3Key="ACCESS_KEY_ID"
    s3Secret="SECRET_ACCESS_KEY"
    signature=`echo -n ${stringToSign} | openssl sha1 -hmac ${s3Secret} -binary | base64`
    curl -H "Host: ${bucket}.s3.amazonaws.com" \
         -H "Date: ${dateValue}" \
         -H "Content-Type: ${contentType}" \
         -H "Authorization: AWS ${s3Key}:${signature}" \
         https://${bucket}.s3.amazonaws.com/${awsFile} -o $outputFile
    

提交回复
热议问题