Skip to content

Commit

Permalink
📝 (s3) Add s3 configuration detailed instructions
Browse files Browse the repository at this point in the history
  • Loading branch information
baptisteArno committed Oct 9, 2023
1 parent 8e54824 commit 021cae3
Show file tree
Hide file tree
Showing 2 changed files with 118 additions and 29 deletions.
30 changes: 1 addition & 29 deletions apps/docs/docs/self-hosting/configuration.md
Original file line number Diff line number Diff line change
Expand Up @@ -147,35 +147,7 @@ Used for uploading images, videos, etc... It can be any S3 compatible object sto

Note that for AWS S3, your endpoint is usually: `s3.<S3_REGION>.amazonaws.com`

Your bucket must have the following policy that tells S3 to allow public read when an object is located under the public folder:

```json
{
"Version": "2012-10-17",
"Statement": [
{
"Sid": "PublicRead",
"Effect": "Allow",
"Principal": "*",
"Action": "s3:GetObject",
"Resource": "arn:aws:s3:::<BUCKET_NAME>/public/*"
}
]
}
```

You also need to configure CORS so that an object can be uploaded from the browser:

```json
[
{
"AllowedHeaders": ["*"],
"AllowedMethods": ["PUT", "POST"],
"AllowedOrigins": ["*"],
"ExposeHeaders": ["ETag"]
}
]
```
In order to function properly, your S3 bucket must be configured. Make sure to read through the [S3 configuration](./guides/s3) doc.

## Giphy (GIF picker)

Expand Down
117 changes: 117 additions & 0 deletions apps/docs/docs/self-hosting/guides/s3.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,117 @@
# S3 configuration

In order for Typebot to store your uploaded files, you need to configure an S3 bucket.

You can use any S3-compatible storage provider. Here are some examples:

- [AWS S3](https://aws.amazon.com/s3/)
- [DigitalOcean Spaces](https://www.digitalocean.com/products/spaces/)
- [Wasabi](https://wasabi.com/)
- [MinIO](https://min.io/)

:::note
If you are self-hosting using Docker, you can follow the [docker-specific instructions](./docker#s3-storage) to run a local S3-compatible storage server.
:::

To function properly, your S3 bucket must have the following configuration:

- CORS policy:

```json
{
"CORSRules": [
{
"AllowedOrigins": ["*"],
"AllowedMethods": ["GET"],
"AllowedHeaders": ["*"],
"MaxAgeSeconds": 3000
}
]
}
```

- Access policy:
```json
{
"Version": "2012-10-17",
"Statement": [
{
"Sid": "PublicRead",
"Effect": "Allow",
"Principal": "*",
"Action": "s3:GetObject",
"Resource": "arn:aws:s3:::<bucket-name>/public/*"
}
]
}
```

## How to set up CORS policy?

Some S3 providers like AWS provide a user interface that allows you to directly enter a bucket policy. However, other providers might not provide such an interface. In this case, you can set up the CORS policy from the command line.

1. Make sure you have the AWS CLI (Command Line Interface) installed and configured on your machine. If you haven't done so already, refer to the official AWS CLI documentation for installation and configuration instructions.

2. Open your command-line interface (CLI), such as Terminal on macOS or Command Prompt on Windows.

3. Create a JSON file (e.g., cors-policy.json) that contains the desired CORS policy. Here's an example CORS policy that allows GET requests from all origins (\*):

```json
{
"CORSRules": [
{
"AllowedOrigins": ["*"],
"AllowedMethods": ["GET"],
"AllowedHeaders": ["*"],
"MaxAgeSeconds": 3000
}
]
}
```

4. Run the following command, replacing `<bucket-name>` with the name of your S3 bucket and `<path-to-policy>` with the file path to your JSON CORS policy file:

```bash
aws s3api put-bucket-cors --bucket <bucket-name> --cors-configuration file://<path-to-policy>
```

When the command is executed successfully, AWS will respond with the JSON representation of the CORS configuration. This indicates that the CORS policy has been applied to your S3 bucket.

Note: Ensure that you have the appropriate AWS credentials and permissions to perform this action.

## How to set up Access policy?

Some S3 providers like AWS provide a user interface that allows you to directly enter a bucket policy. However, other providers like DigitalOcean do not provide such a user interface. In this case, you can set up a bucket policy from the command line.

To set up an S3 bucket policy from the command line, you can use the AWS Command Line Interface (CLI). Here's a step-by-step guide:

1. Install and configure the AWS CLI on your machine if you haven't done so already. You can refer to the official AWS CLI documentation for instructions on installation and configuration.

2. Open your command-line interface (e.g., Terminal on macOS or Command Prompt on Windows).

3. To set up a bucket policy, you need the policy document in JSON format. Create a JSON file (e.g., bucket-policy.json) containing the desired policy. Here's an example policy that allows Public read access for all objects within the bucket:

```json
{
"Version": "2012-10-17",
"Statement": [
{
"Sid": "PublicRead",
"Effect": "Allow",
"Principal": "*",
"Action": "s3:GetObject",
"Resource": "arn:aws:s3:::<bucket-name>/public/*"
}
]
}
```

4. Replace `<bucket-name>` with the name of your S3 bucket.

5. Run the following command, replacing `<bucket-name>` with the name of your S3 bucket and `<path-to-policy>` with the file path to your JSON policy document:

```bash
aws s3api put-bucket-policy --bucket <bucket-name> --policy file://<path-to-policy>
```

After running the command, AWS will respond with the policy's JSON representation if the operation is successful. You should see the response output confirming the policy has been added to the bucket.

1 comment on commit 021cae3

@vercel
Copy link

@vercel vercel bot commented on 021cae3 Oct 9, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Successfully deployed to the following URLs:

docs – ./apps/docs

docs.typebot.io
docs-typebot-io.vercel.app
docs-git-main-typebot-io.vercel.app

Please sign in to comment.