Issue
I want to write a bash script to generate aws pre-signed url to download file stored on s3 bucket.
I generate presign url using browser and use it to download. I need to automate the process to eliminate the need of manually generating link every time.
Solution
We can use awscli to generate the presign URL for downloading purposes. I am attaching a sample snippet which I use to generate the pre-signed URL and download it
# pass aws s3 file path as the first argument
AWS_FILE=$1
pre_sign_url=$(aws s3 presign $AWS_FILE --expires-in 3600 --region 'us-east-2')
# flag --expires-in is the time for which the link is valid, in seconds
# --region region for the bucket, does not need to pass if configured in the CLI
# If you want to download the file specifying the file path
FILENAME=$2
wget -O "$FILENAME" "$pre_sign_url"
# -O flag is to set name for the file
Answered By - nilbarde Answer Checked By - Pedro (WPSolving Volunteer)