# S3 compatible storage (AWS, MinIO)

### Introduction

Our application supports integration with either **AWS S3** or **MinIO** for file storage. Both services offer S3-compatible APIs, allowing you to choose based on your preference or infrastructure needs.

* **AWS S3**: A highly scalable object storage service from Amazon Web Services, widely used for storing and retrieving any amount of data at any time, providing strong security, durability, and low-latency performance.
* **MinIO**: An open-source, high-performance object storage service compatible with Amazon S3 APIs, ideal for on-premise or private cloud deployments, offering a cost-effective alternative to AWS S3.

### AWS

{% embed url="<https://docs.aws.amazon.com/>" %}

**Creating an S3 Bucket**

1. Log in to the **AWS Management Console**.
2. Go to the **S3 Dashboard** and click **Create bucket**.
3. Enter a unique name for your bucket and complete the setup steps.

**Creating an IAM User**

1. In the **IAM Dashboard**, click **Users** > **Create user**.
2. Select **Programmatic access**.
3. Create a username and note the access key ID and secret access key.

{% hint style="info" %}
**Permissions**: Attach the user with the S3 permissions by assigning a suitable policy, either a predefined S3 access policy or a custom one.
{% endhint %}

#### API

#### install dependencies

```bash
yarn add nestjs-s3
```

#### Setup variables

{% code title=".env" %}

```
AWS_S3_REGION= Your Aws Acoount region
AWS_S3_ACCESS_KEY= Created User Access Key Id
AWS_S3_SECRET_ACCESS_KEY= Created User Access Key Secret
```

{% endcode %}

{% code title="constants.ts" %}

```typescript
AWS_S3_REGION: process.env.AWS_S3_REGION,
AWS_S3_ACCESS_KEY: process.env.AWS_S3_ACCESS_KEY,
AWS_S3_SECRET_ACCESS_KEY: process.env.AWS_S3_SECRET_ACCESS_KEY,
```

{% endcode %}

{% code title="s3-bucket-name.enum.ts" %}

```typescript
export enum S3BucketName {
    S3DefaultBucket = 'your bucket name',
}
```

{% endcode %}

#### Initialize S3 Module&#x20;

```typescript
S3Module.forRoot({
    config: {
        credentials: {
            accessKeyId: constants.AWS_S3_ACCESS_KEY,
            secretAccessKey: constants.AWS_S3_SECRET_ACCESS_KEY,
        },
        region: constants.AWS_S3_REGION,
    },
}),
```

### MinIO

#### Adding MinIO as an Alternative Storage Solution

MinIO is a highly scalable, distributed object storage system designed for high-performance applications. By integrating MinIO with your application, you can provide users with a reliable and secure way to store and retrieve data.

* **Create a MinIO Account**: Go to MinIO Console and register. Alternatively, if you’re self-hosting, you can download the MinIO server for your platform from the [MinIO Download Page](https://min.io/download).
* **Set Up MinIO Hosting**:
  * **Local Installation**: Run `minio server /path/to/storage` to start a local MinIO server.
  * **Cloud Installation**: Use cloud hosting providers offering MinIO or configure a MinIO instance in your chosen environment.

#### API

#### Setup enviroment variables

{% code title=".env" %}

```
AWS_S3_HOST=Your MinIO Host
AWS_S3_ACCESS_KEY=Your MinIO Access Key
AWS_S3_SECRET_ACCESS_KEY=Your MinIO Secret Key
AWS_S3_REGION=Your MinIO Region
```

{% endcode %}

{% code title="constants.ts" %}

```typescript
AWS_S3_REGION: process.env.AWS_S3_REGION,
AWS_S3_ACCESS_KEY: process.env.AWS_S3_ACCESS_KEY,
AWS_S3_SECRET_ACCESS_KEY: process.env.AWS_S3_SECRET_ACCESS_KEY,
AWS_S3_HOST: process.env.AWS_S3_HOST
```

{% endcode %}

#### Add MinIO specific params to S3 configuration

{% code title="app.module.ts" %}

```typescript
S3Module.forRoot({
    config: {
        credentials: {
            accessKeyId: constants.AWS_S3_ACCESS_KEY,
            secretAccessKey: constants.AWS_S3_SECRET_ACCESS_KEY,
        },
        region: constants.AWS_S3_REGION,
        
        //Note: use parameters below for setting up minio service instead of AWS S3
        endpoint: constants.AWS_S3_HOST,
        forcePathStyle: true,
    },
}),
```

{% endcode %}

***

{% embed url="<https://min.io/docs/kes/tutorials/getting-started/>" %}


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://intercode.gitbook.io/intercode-saas-kit/external-integrations/s3-compatible-storage-aws-minio.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
