This is an application of the S3 pre-signed post feature. Pre-signed posts can be created and shared with someone who then uses the pre-signed post as a target to POST a file.
The benefit of pre-signed posts is you do not need a set of personal AWS keys to use it e.g. you could give the details for a pre-signed post to anyone and they can use those details a file to your s3 bucket.
A pre-signed post is really a combination of url plus a number of other parameters (documented in the table on this page).
This serverless application shows how to automate the creation of pre-signed posts. It imagines a scenario where you (admin) want to quickly create custom forms to share with people so they can upload a file to your s3 bucket (e.g. maybe people frequently need to send you large files which can't be emailed because of the file size).
./lambda\_deploy.sh <bucket_name>
packages will be uploaded to <bucket_name>/apps/aws-s3-uploader-tool
which is where the lambda resources in the cloudformation template is expecting the zip files to be.
Create stack using cf.yml
Stack Name
: 'aws-s3-uploader-tool'NotificationEmailAddress
: notification emails will be sent to this address whenever someone uploads a fileS3PublicBucket
: html forms and uploaded files will be put in this bucketS3ResourceBucket
: the bucket where you uploaded the lambdas (in the instructions above)
Take a look at sample_payload.json
and modify as needed.
Note: expiry is in seconds
Install jq or the last line from the command below. jq is very useful for parsing JSON
aws lambda invoke \
--function-name aws-s3-uploader-tool_generatePresignPOST \
--payload file://sample_payload.json \
outfile.txt && cat outfile.txt \
| jq '.[] | .id + ": " + .form_link' --raw-output
Example output:
person1: https://s3-ap-southeast-2.amazonaws.com/<bucket>/public/25bf0679/index.html
person2: https://s3-ap-southeast-2.amazonaws.com/<bucket>/public/7bc5facc/index.html
To understand how this application works, goto one of the output urls. The page will look something like this:
Notice that the url path contains public/ - this is a section of the bucket that is publicly GETable by anyone (determined by the policy attached to the bucket)
Drop in a file and it will instantly upload. The file will be uploaded to the uploads/ directory. This section is not public.
Once the file is uploaded, a lambda function will be triggered and the html form will be removed.