Upload to S3 with expiring link

Upload a file to S3, and create a temporary link for it.

#!/bin/bash
# Add a file to s3 with temporary url, optionally specified in the command line.
if [ -z "$2" ] ; then
    echo "Need at least two arguments:  local source and s3 destination (e.g. file.txt s3://my-bucket/dir)"
	echo "3rd (optional) argument is expiration sends."
	exit 1
fi

if [ -z "$3" ]
  then
    export exp=3600
  else
    export exp=$3
fi

aws s3 cp $1 $2/$1
aws s3 presign $2/$1 --expires-in $exp

echo "expires in $exp seconds"

Leave a Reply

Your email address will not be published. Required fields are marked *