Skip to content

Files

Latest commit

117a3aa · Apr 20, 2020

History

History
45 lines (29 loc) · 1.07 KB

README.md

File metadata and controls

45 lines (29 loc) · 1.07 KB

S3 Pre-signed URLs from Lambda using Serverless

Generate S3 pre-signed URLs for uploading files from AWS Lambda using Serverless Framework.

No setup required, just deploy using serverless.

The generated signed URL from the lambda can be used to upload files from the browser using a PUT.

Includes:

  • Creates a Lambda Function with IAM Role to allow s3:PutObject
  • Sets up API gateway for GET /signed-upload-url
  • Generates S3 Bucket with correct CORS and policy for public reads s3:GetObject

How to deploy:

  1. Install Serverless Framework
npm i -g serverless
  1. Deploy using:
serverless deploy
  1. Visit lambda url and get signed upload url:
https://yourlamdba.execute-api.us-east-1.amazonaws.com/dev/signed-upload-url
  1. Test your signed url using curl to upload a file
curl --upload-file ~/Desktop/test.png https://your-s3-bucket.s3.amazonaws.com/test.png?AWSAccessKeyId=ASIAJFHAKGG77U4KC&Expires=1587360000&Signature=cHAGKh3hHFASncccMQ2kgI=
  1. View/Download uploaded file:
https://your-s3-bucket.s3.amazonaws.com/test.png