Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/jbenesch/micro-s3-getSignedUrl
AWS S3 signed url micro service for https://github.com/zeit/micro
https://github.com/jbenesch/micro-s3-getSignedUrl
aws-s3 micro microservice
Last synced: 2 months ago
JSON representation
AWS S3 signed url micro service for https://github.com/zeit/micro
- Host: GitHub
- URL: https://github.com/jbenesch/micro-s3-getSignedUrl
- Owner: jbenesch
- License: mit
- Created: 2017-03-06T07:45:34.000Z (almost 8 years ago)
- Default Branch: master
- Last Pushed: 2017-03-06T10:46:00.000Z (almost 8 years ago)
- Last Synced: 2024-08-01T22:46:13.591Z (5 months ago)
- Topics: aws-s3, micro, microservice
- Language: JavaScript
- Size: 24.4 KB
- Stars: 13
- Watchers: 2
- Forks: 1
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# micro-s3-getSignedUrl
AWS S3 signed url micro service for https://github.com/zeit/micro## Getting Started
1. Clone this repo
2. Create a .env file: `touch .env` (see next section for contents)
3. Install dependencies: `yarn`
4. Generate an auth token: `yarn run token` (make sure to also add this to .env file)
5. Start the micro service: `yarn start`Now to generate a signed url:
`curl -H 'Authorization: Bearer TOKEN_CREATED_IN_STEP_4' http://localhost:3000/?name=fileName.jpg&type=image/jpeg`## Environment Variables Needed
```
AWS_ACCESS_KEY=YOUR_ACCESS_KEY
AWS_SECRET_KEY=YOUR_SECRET_KEY
AWS_S3_BUCKET=YOUR_BUCKET_NAME
AWS_REGION=us-east-1
JWT_PRIVATE_KEY=CREATE_PRIVATE_KEY
```## Launching Micro Service With Now
1. Add all of your environment variables to now secrets: (see below)
2. Deploy!```
now secrets add aws_access_key "YOUR_ACCESS_KEY"
now secrets add aws_secret_key "YOUR_SECRET_KEY"
now secrets add aws_s3_bucket "YOUR_BUCKET_NAME"
now secrets add jwt_private_key "CREATE_PRIVATE_KEY"
```
`now -e AWS_ACCESS_KEY=@aws_access_key -e AWS_SECRET_KEY=@aws_secret_key -e AWS_S3_BUCKET=@aws_s3_bucket -e JWT_PRIVATE_KEY=@jwt_private_key`## Example React Component
```
import React, { Component } from 'react';
import Dropzone from 'react-dropzone';
import { NOW_URL, JWT_TOKEN } from '../env';class App extends Component {
onDrop = (acceptedFiles, rejectedFiles) => {
acceptedFiles.forEach(file => {
fetch(`${NOW_URL}/?name=${file.name}&type=${file.type}`, {
headers: {
'Accept': 'application/json',
'Content-Type': 'application/json',
'Authorization': `Bearer ${JWT_TOKEN}`
}
})
.then(res => res.json())
.then(signed => fetch(signed.url, {
method: 'PUT',
body: file
}));
});
}render() {
return (
Try dropping some files here, or click to select files to upload.
);
}
}export default App;
```