# Connecting AWS S3 Storage

### Creating a Bucket

1. Go to the AWS console ([link](https://console.aws.amazon.com/)). Navigate to **"All services"** -> **"Storage"** -> **"S3"**.

<figure><img src="https://835495363-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FsZ8acWnNlSalIHQjMFu1%2Fuploads%2FqwsPXfqb5v3slflv3C91%2FawsS3section.png?alt=media&#x26;token=f7e7824a-a48c-4d7f-a3b7-6ebf09b03105" alt=""><figcaption><p>"S3" section in AWS</p></figcaption></figure>

2. Click **"Create bucket"**.

<figure><img src="https://835495363-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FsZ8acWnNlSalIHQjMFu1%2Fuploads%2F11hJCTdpDzgXWnw3TdA2%2FawsS3createBucketBtn.png?alt=media&#x26;token=17ef8736-1e2a-4343-b6ab-81423b77d418" alt=""><figcaption><p>Button for creating a bucket</p></figcaption></figure>

3. Enter any name for the bucket (field **"Bucket name"**). Leave all other parameters as default and click **"Create bucket".**

<figure><img src="https://835495363-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FsZ8acWnNlSalIHQjMFu1%2Fuploads%2FkhorL2nZ0qPJlUc5upWv%2FawsS3bucketParametersUpdated.png?alt=media&#x26;token=fbb200a4-2046-455f-a9d7-77293ebc21d8" alt=""><figcaption><p>Parameters of the bucket being created</p></figcaption></figure>

### Creating an IAM User and Access Keys

1. Go to **"All services"** -> **"Security, Identity, & Compliance"** -> **"IAM"**.

<figure><img src="https://835495363-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FsZ8acWnNlSalIHQjMFu1%2Fuploads%2FwMyzRzKKeyfu7IydJJaI%2FawsS3IAMSection.png?alt=media&#x26;token=d4792b08-281b-49cd-a9ad-26244d59a833" alt=""><figcaption><p>"IAM" section</p></figcaption></figure>

2. Next, create a new IAM user. Go to the **"Access Management"** tab, then **"Users"**. Click **"Create user"**.

<figure><img src="https://835495363-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FsZ8acWnNlSalIHQjMFu1%2Fuploads%2FEut4YDnGwKxwWZpSnfRI%2FawsS3CreateUserBtn.png?alt=media&#x26;token=cee22dd0-2666-4f7e-9720-a3a955260d3f" alt=""><figcaption><p>Creating a new IAM user</p></figcaption></figure>

3. Enter the name of the IAM user in the **"User name"** field.

Click **"Next"**.

<figure><img src="https://835495363-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FsZ8acWnNlSalIHQjMFu1%2Fuploads%2FXP536xlDaFbzDsFCURTq%2FawsS3userDetails.png?alt=media&#x26;token=8fa6e27a-93e5-4301-b133-4e8ed32f9922" alt=""><figcaption><p>"Specify user details" tab</p></figcaption></figure>

4. Select **"Attach policies directly"** as the **"Permissions options"**. Scroll down the page.

<figure><img src="https://835495363-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FsZ8acWnNlSalIHQjMFu1%2Fuploads%2FRftxxktNadaV7Bez8Zx7%2FawsS3AttachPoliciesDirectly.png?alt=media&#x26;token=fb6ff20a-ede0-44cc-91f2-eee0023fd49a" alt=""><figcaption><p>Selecting "Permissions options"</p></figcaption></figure>

5. In the **"Permissions policies"** section click **"Create policy"**.

<figure><img src="https://835495363-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FsZ8acWnNlSalIHQjMFu1%2Fuploads%2FShf1yPd800ompOXJjw3l%2FawsS3CreatePolicy.png?alt=media&#x26;token=24aa8110-79f6-421b-92ed-74801fd8c265" alt=""><figcaption><p>"Create policy" button</p></figcaption></figure>

6. In the newly opened tab, in the **"Policy editor"**, select **"JSON"** as the format and paste the following content into the parameters field:

```json
{
  "Version": "2012-10-17",
  "Statement": [
    {
      "Effect": "Allow",
      "Action": [
        "s3:PutObject",
        "s3:GetObject",
        "s3:DeleteObject",
        "s3:ListBucket"
      ],
      "Resource": [
        "arn:aws:s3:::your-bucket-name",
        "arn:aws:s3:::your-bucket-name/*"
      ]
    }
  ]
}
```

{% hint style="warning" %}
Replace **"your-bucket-name"** with the name of the bucket you created earlier (in this guide — **"aws-s3-mikopbxstorage"**).
{% endhint %}

Click **"Next"**.

<figure><img src="https://835495363-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FsZ8acWnNlSalIHQjMFu1%2Fuploads%2FOK3do8FHKeQLYjAYBDLJ%2FawsS3CreatingNewPolicyS1.png?alt=media&#x26;token=1d25f1b8-ef45-481f-8db1-ea690f7f7fc0" alt=""><figcaption><p>Creating a new policy. Step 1</p></figcaption></figure>

7. Next, specify any name for the policy being created.

Click **"Next"**.

<figure><img src="https://835495363-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FsZ8acWnNlSalIHQjMFu1%2Fuploads%2FmhUIptmI3QAdwEONl3bK%2FawsS3access-mikopbx.png?alt=media&#x26;token=81c6c3de-2ca4-40e8-b15a-d8a068eaba5c" alt=""><figcaption><p>Creating a new policy. Step 2</p></figcaption></figure>

8. Return to the user creation tab, refresh the policy list, and select the previously created policy (in this guide — **"access-mikopbx"**).

Click **"Next"**.

<figure><img src="https://835495363-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FsZ8acWnNlSalIHQjMFu1%2Fuploads%2FUrDugjU56CZ3CWAqvk73%2FawsS3ChoosingPolicy.png?alt=media&#x26;token=a601a613-ec52-444a-b984-e9c7d1ff8c65" alt=""><figcaption><p>Selecting the previously created policy</p></figcaption></figure>

9. Confirm user creation: click **"Create user"**.

<figure><img src="https://835495363-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FsZ8acWnNlSalIHQjMFu1%2Fuploads%2Fah9uv74KVA0fgLh1B34M%2FawsS3ConfirmationOfUserCreation.png?alt=media&#x26;token=5317733d-cfc4-4d58-ba44-11cdcde7d9c9" alt=""><figcaption><p>Confirming user creation</p></figcaption></figure>

10. Open the page of the created user by clicking on the username.

<figure><img src="https://835495363-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FsZ8acWnNlSalIHQjMFu1%2Fuploads%2FxWsT5SCIEMu5QqSujoj4%2FawsS3Username.png?alt=media&#x26;token=b074fbf9-cb92-4dca-bd85-e8df86f8ee5a" alt=""><figcaption><p>Opening the created user's page</p></figcaption></figure>

11. Go to the **"Security credentials"** section. Click **"Create access key"**.

<figure><img src="https://835495363-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FsZ8acWnNlSalIHQjMFu1%2Fuploads%2F7KZvSJsjjsRo403U9HQL%2FawsS3createAccessKeyBtn.png?alt=media&#x26;token=f1ff463c-e5e0-4f20-bfdb-f1c79026dc0c" alt=""><figcaption><p>Creating an access key</p></figcaption></figure>

12. Select **"Application running outside AWS"**. Click **"Next"**.

<figure><img src="https://835495363-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FsZ8acWnNlSalIHQjMFu1%2Fuploads%2FS4VDOfkA5xXlkzATjPiQ%2FawsS3ApplicationRunningOutside.png?alt=media&#x26;token=9f318853-6485-4164-bd95-0392b240722c" alt=""><figcaption><p>Selecting parameters when creating the key</p></figcaption></figure>

13. Enter a description for the key so that you can identify it later. Click **"Create access key"**.

<figure><img src="https://835495363-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FsZ8acWnNlSalIHQjMFu1%2Fuploads%2FTmqG3OIczY0USfhQwm3j%2FawsS3Params.png?alt=media&#x26;token=9671d37d-a03c-4240-88f0-c3dee2760825" alt=""><figcaption><p>Key description</p></figcaption></figure>

The **Access key** and **Secret access key** will be displayed. Save them — they will be needed later when configuring MikoPBX.

{% hint style="warning" %}
The secret access key can only be viewed or downloaded now. It cannot be recovered later.
{% endhint %}

<figure><img src="https://835495363-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FsZ8acWnNlSalIHQjMFu1%2Fuploads%2F4Zyoj3jU93lV9iZouMcF%2FawsS3CreatedAccessKey.png?alt=media&#x26;token=4dbd1d78-deba-43da-b92e-f1296b9c1bff" alt=""><figcaption><p>Access key and Secret access key</p></figcaption></figure>

### Connecting to MikoPBX

1. Go to the **"Maintenance"** -> **"Storage"** tab.

<figure><img src="https://835495363-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FsZ8acWnNlSalIHQjMFu1%2Fuploads%2FbiJPZsIEfMa9aT1tNvCx%2FstorageSectionMikoPBX-cut.png?alt=media&#x26;token=f8eccead-5fce-4959-8759-cf953ee700bb" alt=""><figcaption><p>"Maintenance" -> "Storage" section</p></figcaption></figure>

2. Open the **"S3 Cloud Storage"** tab and fill in the following fields:

* **Automatic recording upload to cloud storage** — enable the switch.
* **S3 endpoint URL** — enter the S3 AWS endpoint depending on the region of your bucket ([link](https://docs.aws.amazon.com/general/latest/gr/s3.html) to the table with all URLs). In this guide — `https://s3.ap-southeast-1.amazonaws.com`
* **S3 region** — specify the **region of your bucket**. In this guide — `ap-southeast-1`
* **S3 bucket name** — enter the name of the bucket created in AWS (for example `aws-s3-mikopbxstorage` in this guide)
* **Access key** and **Secret key** — paste the values obtained when creating the service account access key.

Configure the **“Local storage period (S3 mode)”** slider — choose how long recordings will be stored locally before being deleted after uploading to the cloud.

{% hint style="info" %}
Shorter local storage periods free up disk space faster.
{% endhint %}

Click **“Save”**.

<figure><img src="https://835495363-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FsZ8acWnNlSalIHQjMFu1%2Fuploads%2FjBoSuAen4EQOxHOdjE0R%2FENmikopbxStorageParamsAWS.png?alt=media&#x26;token=67b905d9-7237-4b22-9cf5-899613c0c081" alt=""><figcaption><p>Parameters for connecting S3 cloud storage in MikoPBX</p></figcaption></figure>

After saving the settings, click **"Test connection"**. If the connection is successful, the message **“S3 connection successful”** will appear and synchronization of call recordings will begin.

<figure><img src="https://835495363-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FsZ8acWnNlSalIHQjMFu1%2Fuploads%2FZY2PY90FCxKj1SXzR0z1%2FENsuccessfulConnectionS3AWS.png?alt=media&#x26;token=c2fe407d-a744-4959-8f8c-52923a17ac86" alt=""><figcaption><p>Successful connection</p></figcaption></figure>
