Skip to content

Automatically provisions unique html forms for file upload to s3

Notifications You must be signed in to change notification settings

gsat-technology/aws-s3-uploader-tool

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

10 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

aws-s3-uploader-tool

About

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).

alt tag

deploy

upload lambda deployment packages to s3

./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 Cloudformation Stack

Create stack using cf.yml

  • Stack Name: 'aws-s3-uploader-tool'
  • NotificationEmailAddress: notification emails will be sent to this address whenever someone uploads a file
  • S3PublicBucket: html forms and uploaded files will be put in this bucket
  • S3ResourceBucket: the bucket where you uploaded the lambdas (in the instructions above)

Create some forms

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:

alt tag

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.

About

Automatically provisions unique html forms for file upload to s3

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages