This repository consists of two lambdas, each with their own CloudFormation templates for provisioning roles, and deploying the lambda packages to the AWS surface. The http-api-triggered-lambda/s3-signed-upload-with-http-api.yaml file will also create an AWS API Gateway HTTP API for invoking the NodeJS entry point and returning to you the signed URL for the upload operation.
-
http-api-triggered-lambda: receives a request from react-s3-uploader via the HTTP API created in the corresponding CloudFormation template and returns a signed URL. The signed URL is for upload within a bucket folder and contains sample metadata, as these two S3 upload problem variants have their own challenges I thought I would provide an example on how to solve them here.
-
s3-upload-trigger: An S3 trigger destination lambda which extracts the metadata and converts the contents of the object to a Base64 encoded string. The idea being; you can now store this string in DynamoDB or Aurora and let your S3 Lifecycle Policy handle archiving and removal for you.
Clone or fork this repository, and verify you have the SAM CLI installed first. Once you have a working sam
CLI and you have properly stored your AWS credentials on your local machine, you are ready to run the following:
- http-api-triggered-lambda/zip-and-upload-cmd-template.sh (modify the s3 bucket where you would like these lambda deployment packages staged)
- http-api-triggered-lambda/s3-signed-upload-with-http-api.yaml (follow instructions in comments at the top)
- s3-upload-trigger/zip-and-upload-cmd-template.sh (modify the s3 bucket where you would like these lambda deployment packages staged)
- s3-upload-trigger/s3-upload-trigger.yaml (follow instructions in comments at the top)
Easiest use case is via react-s3-uploader
<ReactS3Uploader
signingUrl="https://<your-api-id>.execute-api.<region>.amazonaws.com/"
signingUrlMethod="GET"
accept="image/*"
signingUrlQueryParams={{ key1: 'Key one', key2: 'Key two' }}
uploadRequestHeaders={{}}
onFinish={onUploadFinish}
onProgress={onUploadProgress}
style={uploaderStyle}
/>
At the time I created this repository, I was using version 5.0.0.
- Fork this repository
- Create your feature branch:
git checkout -b my-new-feature
- Commit your changes:
git commit -am 'Add some feature'
- Push to the branch:
git push origin my-new-feature
- Submit a pull request :D
Daniel Kemper (Author)
Licensed under the MIT license for open source code
TODO: Write license