Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

aws-config and aws-storage cookbooks from Aexol #235

Open
wants to merge 5 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions docs/cookbook/web/_sidebar.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,9 @@
- [Comprehend](/solutions/aws-comprehend)
- Bots
- [Facebook Weather Bot](/solutions/weather-bot)
- AWS
- [Configuration](/solutions/aws-config)
- [Storage on S3](/solutions/aws-storage)
- Auth sockets
- [Face authentication](/solutions/face-auth)
- Deployment
Expand Down
41 changes: 41 additions & 0 deletions docs/cookbook/web/solutions/aws-config.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
## AWS Configuration

- Preparation: **2 minutes**
- Requirements:
- Initiated Syncano project
- AWS ACCOUNT_KEY
- AWS SECRET
- Sockets:
- [aws-config](https://syncano.io/#/sockets/aws-config)

## Problem

To configure an AWS service, you'll need to provide `AWS_ACCESS_KEY_ID`, `AWS_SECRET_ACCESS_KEY` and `REGION`.

## Solution

This Socket provides a configuration endpoint and can is a base for the following AWS sockets: `aws-storage`, `aws-wordpress`, `aws-node`, `aws-ethereum` and `aws-ls`

## Installing dependencies

To install `aws-config` type:
```sh
$ npx s add aws-config
$ npx s deploy
```

Now you have to provide ACCOUNT_KEY and SECRET key for the AWS Service:
```sh
$ npx s call aws-config/install
```

#### AWS_ACCESS_KEY_ID
An access key to your AWS account.

#### AWS_SECRET_ACCESS_KEY
A secret key to your AWS account.

#### REGION
A region on which your instance will operate.

To take advantage of a configured AWS account, see the [aws-storage](https://syncano.io/#/sockets/aws-storage) Socket that communicates with S3 and makes it super easy to use this service.
157 changes: 157 additions & 0 deletions docs/cookbook/web/solutions/aws-storage.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,157 @@
# AWS S3 Storage

- Preparation: **5 minutes**
- Requirements:
- Initiated Syncano project
- config with [aws-config](/solutions/aws-config)
- Sockets:
- [aws-storage](https://syncano.io/#/sockets/aws-storage)

## Problem to solve

It's very common that an application needs a file storage for user data. While Syncano provides this functionality with a `file` type in Data Objects, there may be cases where a custom solution is more suitable.

## Solution

A socket providing an integration with an S3 storage on AWS and solving the following use cases:
- [Storing files that are accessible only by their owner](#user-managed-files)
- [Storing files that are owned by a user and available for other selected users](#socket-managed-files)
- [Admin managed files](#upload-files-from-sockets)

#### Pre installation
If you haven't done that already please [configure](/solutions/aws-config) your Syncano instance

#### Installing dependencies

To install `aws-storage` type:
```sh
$ npx s add aws-storage
$ npx s deploy
```


### User managed files
You want to store files that are owned by a user and only show it to that user. Call that url with `_user_key` as a parameter or being logged in within Syncano client library.

#### Get upload links for user files( recommended )

Instead of transferring files with put you can receive temporary user upload link which will allow to send file directly to AWS

**Required parameters:**

`name=[string]` - file name

`_user_key=[string]` - user key only when not using syncano-client library
```
https://<your_instance_name>.syncano.space/aws-storage/user-upload-link/
```
After that call you will receive temporary upload link with which you can upload your file directly to S3

#### Reading a file

Then you can retrieve your file

**Required parameters:**

`name=[string]` - file name

`_user_key=[string]` - user key only when not using syncano-client library
```
https://<your_instance_name>.syncano.space/aws-storage/user-read/
```

#### Put base 64 files
You can also put files directly with POST request if you need so.

**Required parameters:**

`file=[string]` - base 64 encoded file

`name=[string]` - file name

`_user_key=[string]` - user key only when not using syncano-client library
```
https://<your_instance_name>.syncano.space/aws-storage/user-upload/
```


### Socket managed files

You want to store files that are private and you want to decide who will have access to them. This use case is very handy in social services backend. There you usually face the problem with image privacy. This is a plug-n-play solution!

#### Retrieve many files

Remember to only use this socket inside backend code.
```javascript
import Syncano from '@syncano/core'
export default async ctx => {
const {data, response, socket} = new Syncano(ctx)
try {
const {user} = ctx.meta
const fileLinks = await socket.post('aws-storage/make-links', {
fileNames: [`${user.username}/file1.txt`, `${user.username}/file2.txt`]
})
return response.json(fileLinks)
} catch ({message}) {
return response.json(message, 400)
}
}
```

### Upload files from sockets
99% of use cases are covered by above solutions. However, sometimes we need a more complicated administrator upload.

#### Upload from socket with link

Example backend code

**Required parameters:**

`name=[string]` - file name

`_user_key=[string]` - user key only when not using syncano-client library

```javascript
import Syncano from '@syncano/core'
export default async ctx => {
const {data, response, socket} = new Syncano(ctx)
try {
const {name} = ctx.args
const fileLink = await socket.post('aws-storage/admin-upload-link', {
name
})
return response.json(fileLink)
} catch ({message}) {
return response.json(message, 400)
}
}
```

#### Upload from socket with put

Example backend code

**Required parameters:**

`file=[string]` - base 64 encoded file

`name=[string]` - file name

`_user_key=[string]` - user key only when not using syncano-client library

```javascript
import Syncano from '@syncano/core'
export default async ctx => {
const {data, response, socket} = new Syncano(ctx)
try {
const {name,fileb64} = ctx.args
const fileLink = await socket.post('aws-storage/admin-upload', {
name,
file:fileb64
})
return response.json(fileLink)
} catch ({message}) {
return response.json(message, 400)
}
}
```
Loading