script to download file from Amazon S3 bucket

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

    I write this bash script to download file from s3 (I download compressed file, you can change contentType to download other types of file)

    #!/bin/sh 
    outputFile="Your_PATH"
    amzFile="AMAZON_FILE_PATH"
    bucket="YOUR_BUCKET"
    resource="/${bucket}/${amzFile}"
    contentType="application/x-compressed-tar"
    dateValue=`date -R`
    stringToSign="GET\n\n${contentType}\n${dateValue}\n${resource}"
    s3Key="YOUR_S3_KEY"
    s3Secret="YOUR_S3SECRET"
    signature=`echo -en ${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/${amzFile} -o $outputFile
    

提交回复
热议问题