Generate S3 object pre-signed URL in one command
$ s3url s3://my-bucket/foo.key
https://my-bucket.s3-ap-northeast-1.amazonaws.com/foo.key?X-Amz-Algorithm=AWS4-HMAC-SHA256&X-Amz-Credential=AKIA***************************%2Fap-northeast-1%2Fs3%2Faws4_request&X-Amz-Date=20160923T010227Z&X-Amz-Expires=300&X-Amz-SignedHeaders=host&X-Amz-Signature=****************************************************************
Formula is available at dtan4/homebrew-tools.
$ brew tap dtan4/tools
$ brew install s3url
Precompiled binaries for Windows, OS X, Linux are available at Releases.
$ go get -d github.com/dtan4/s3url
$ cd $GOPATH/src/github.com/dtan4/s3url
$ make install
You need to set AWS credentials beforehand, or you can also use named profile written in ~/.aws/credentials
.
export AWS_ACCESS_KEY_ID=XXXXXXXXXXXXXXXXXXXX
export AWS_SECRET_ACCESS_KEY=xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
# or configure them in ~/.aws/credentials
export AWS_REGION=xx-yyyy-0
Just type the command below and get Pre-signed URL on the screen.
# https:// URL (both virtual-hosted-style and path-style)
$ s3url https://BUCKET.s3-region.amazonaws.com/KEY [-d DURATION] [--profile PROFILE] [--upload UPLOAD]
$ s3url https://s3-region.amazonaws.com/BUCKET/KEY [-d DURATION] [--profile PROFILE] [--upload UPLOAD]
# s3:// URL
$ s3url s3://BUCKET/KEY [-d DURATION] [--profile PROFILE] [--upload UPLOAD]
# Using options
$ s3url -b BUCKET -k KEY [-d DURATION] [--profile PROFILE] [--upload UPLOAD]
If target object does not exist in the bucket yet, you can upload file with --upload
flag before getting Pre-signed URL. Following example shows that uploading foo.key
to s3://my-bucket/foo.key
and getting Pre-signed URL of s3://my-bucket/foo.key
will be executed in series.
$ s3url s3://my-bucket/foo.key --upload foo.key
uploaded: /path/to/foo.key
https://my-bucket.s3-ap-northeast-1.amazonaws.com/foo.key?X-Amz-Algorithm=AWS4-HMAC-SHA256&X-Amz-Credential=AKIA***************************%2Fap-northeast-1%2Fs3%2Faws4_request&X-Amz-Date=20160923T010227Z&X-Amz-Expires=300&X-Amz-SignedHeaders=host&X-Amz-Signature=****************************************************************
Option | Description | Required | Default |
---|---|---|---|
-b , -bucket=BUCKET |
Bucket name | Required (if no URL is specified) | |
-k , -key=KEY |
Object key | Required (if no URL is specified) | |
-d , -duration=DURATION |
Valid duration in minutes | 5 | |
--profile=PROFILE |
AWS profile name | ||
--upload=UPLOAD |
File to upload | ||
-h , -help |
Print command line usage | ||
-v , -version |
Print version |
Retrieve this repository and build using make
.
$ go get -d github.com/dtan4/s3url
$ cd $GOPATH/src/github.com/dtan4/s3url
$ make