skip to Main Content

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.

2

Answers


  1. 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
    
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search