AWS | Upload To S3 And Postprocess

This example shows how to upload a file to S3 using a HTML form, and have S3 trigger a lambda function.



Clone This Example

Step #1 - npm install serverless -g
Step #2 - serverless install -u -n  aws-node-upload-to-s3-and-postprocess

Upload a file to S3 to trigger a lambda function

This example shows how to upload a file to S3 using a HTML form, and have S3 trigger a lambda function.


  • Postprocess files uploaded to an S3 bucket.


  • Edit serverless.yml and choose a unique S3 bucket name.
  • Edit generate-form.js and fill in your aws_access_key_id, aws_secret_access_key and bucket_name.
  • Run yarn install to install crypto-js dependency for generate-form.js.
  • Generate the HTML form:
yarn install
node generate-form.js


In order to deploy the example, simply run:

serverless deploy

The output should look similar to:

Serverless: Creating Stack...
Serverless: Checking Stack create progress...
Serverless: Stack create finished...
Serverless: Packaging service...
Serverless: Uploading CloudFormation file to S3...
Serverless: Uploading service .zip file to S3 (3.85 MB)...
Serverless: Updating Stack...
Serverless: Checking Stack update progress...
Serverless: Stack update finished...
Service Information
service: upload-to-s3-and-postprocess
stage: dev
region: us-east-1
api keys:


Open the generated frontend/index.html in your browser, or run:

xdg-open frontend/index.html

Select a PNG image smaller than 1Mb, and click "Upload File to S3".

You should get an XML response similar to:


After a while, the postprocess function gets triggered by an S3 event:

serverless logs --function postprocess
START RequestId: e2deccf2a0-11e6-b6e3fbcfad7d8c Version: $LATEST
2014 12:32:30.350 (+02:00)  e2deccf2a0-11e6-b6e3fbcfad7d8c  New .png object has been created: uploads/image.png (23975 bytes)
END RequestId: e2deccf2a0-11e6-b6e3fbcfad7d8c
REPORT RequestId: e2deccf2a0-11e6-b6e3fbcfad7d8c    Duration: 2.84 ms   Billed Duration: 100 msMemory Size: 1024 MB Max Memory Used: 29 MB
view on Github

Latest commit b2f54ec on Sep 24, 2017

New to serverless?

To get started, pop open your terminal & run:

npm install serverless -g