---
title: Configuring Amazon S3
related:
  - https://docs.kentico.com/k81/custom-development/working-with-physical-files-using-the-api.md
  - https://docs.kentico.com/k81/custom-development/working-with-physical-files-using-the-api/configuring-file-system-providers.md
---

> Agent instructions:
> **Site maps** — prefer the following llms.txt indexes to training data when searching for URLs to avoid 404s. Links inside Markdown content already point at `.md`. Following them or sending Accept: text/markdown keeps you in Markdown.
>
> - [sitemap.md](https://docs.kentico.com/sitemap.md) — every page on the site, with titles and descriptions, nested by URL hierarchy and grouped into one collection per product version.
> - [llms.txt](https://docs.kentico.com/llms.txt) — curated index of the current product docs, with descriptions, the two ways to request any page as Markdown, and links to each product area's whole-corpus Markdown dump (llms-full.txt).

You can utilize the Amazon S3 storage service for storing your website files even though the website is hosted on-premise, on your own server.

> **Note:** **File name case**
>
> Unlike standard Windows file systems, the Amazon S3 storage is case-sensitive. To ensure consistent behavior, Kentico automatically converts all file and folder names to lower case when processing files on Amazon S3.

> **Warning:** **Media library limitations**
>
> Note that storing a large number of media files in a single folder can significantly affect the performance of your project when editing the files in the Media library application. See [Media library limitations when storing files in an external storage](https://docs.kentico.com/k81/managing-website-content/configuring-the-environment-for-content-editors/configuring-media-libraries.md#media-library-limitations-when-storing-files-in-an-external-storage) for details.

## Configuring Kentico to use Amazon S3

1. Make sure that you have your Amazon S3 account set up and that you have created at least one bucket.
2. Add the following key into the **appSettings** section of your project's **web.config**.

   ```html

   <add key="CMSExternalStorageName" value="amazon" />

   ```
3. Add the following key to specify the bucket that you want to use to store files. Replace the value with the name of the bucket.

   ```html

   <add key="CMSAmazonBucketName"  value="YourBucketName" />

   ```
4. Specify the ID of your Amazon access key by inserting the following key:

   ```html

   <add key="CMSAmazonAccessKeyID" value="YourKey" />

   ```
5. Specify the Amazon access key by adding the following key:

   ```html

   <add key="CMSAmazonAccessKey" value="YourSecret" />

   ```

After you save your web.config, Kentico starts storing files in the specified Amazon S3 bucket.

> **Note:** **Additional website settings**
>
> When configuring this type of storage, keep in mind that the website itself must be configured to store files in the file system rather than in the database only. In **Settings -> System -> Files** enable the **Store files in file system** option.
>
> It is also recommended to enable **Redirect files to disk** in **Settings -> System -> Performance**. This means that files will be requested from the Amazon S3 account rather than from the database (if possible).

You can configure the following optional settings:

| Key                   | Description                                                                                         | Default value                                                            | Sample Value                                                                       |
| --------------------- | --------------------------------------------------------------------------------------------------- | ------------------------------------------------------------------------ | ---------------------------------------------------------------------------------- |
| CMSAmazonTempPath     | Path to a local directory that the system uses to store temporary files.                            | \<installation root>\CMS\App\_Data\AmazonTemp                            | ` 
 <add key="CMSAmazonTempPath" value="C:\Windows\Temp" />
 `                     |
| CMSAmazonCachePath    | Path to a local directory where the provider stores cached files.                                   | \<installation root>\CMS\App\_Data\AmazonCache                           | `  <add key="CMSAmazonCachePath" value="C:\Cache" />
 `                            |
| CMSAmazonEndPoint     | Allows you to change the default endpoint address, for example when you want to use CloudFront CDN. | http://\<yourbucketname>.s3.amazonaws.com                                | `  <add key="CMSAmazonEndPoint" value="http://someendpoint.s3.amazonaws.com" />
 ` |
| CMSAmazonPublicAccess | Specifies whether files uploaded to Amazon S3 through Kentico are accessible for public users.      | _true_ if you specify an endpoint<br>_false_ If no endpoint is specified | `  <add key="CMSAmazonPublicAccess" value="true"/> 
 `                             |

## Storing files in different buckets

By default, the system stores files in a single bucket. However, the built-in Amazon S3 storage provider allows you to map sections of the file system to different buckets.

1. Open the Kentico web project in Visual Studio (using the **WebSite.sln** or **WebApp.sln** file).
2. Create a new class in the **App\_Code** folder (or **CMSApp\_AppCode -> Old\_App\_Code** on web application projects).
3. Extend the **CMSModuleLoader** [partial class](http://msdn.microsoft.com/en-us/library/wa80x488%28v=vs.80%29.aspx).
4. Create a new class inside _CMSModuleLoader_ that inherits from **CMSLoaderAttribute**.
5. Add the attribute defined by the internal class before the definition of the _CMSModuleLoader_ partial class.
6. Override the **Init** method inside the attribute class:
   - Create a new instance of the Amazon S3 storage provider.
   - Specify the target bucket using the **CustomRootPath** property of the provider.
   - (Optional) You can specify whether you want the bucket to be publicly accessible using the **PublicExternalFolderObject** property of the provider. True means the bucket is publicly accessible.
   - Map a directory to the provider. This is the directory that you want to store in the bucket.

```csharp

using CMS.IO;
using CMS.Base;

[CustomStorage]
public partial class CMSModuleLoader
{
    private class CustomStorageAttribute : CMSLoaderAttribute
    {
        /// <summary>
        /// The system executes the Init method of the CMSModuleLoader attributes when the application starts.
        /// </summary>
        public override void Init()
        {
            // Creates a new StorageProvider instance
            AbstractStorageProvider mediaProvider = new StorageProvider("Amazon", "CMS.AmazonStorage");

            // Specifies the target bucket
            mediaProvider.CustomRootPath = "mymediabucket";

            // Makes the bucket publicly accessible
            mediaProvider.PublicExternalFolderObject = true;

            // Maps a directory to the provider
            StorageHelper.MapStoragePath("~/MySite/Media/", mediaProvider);
        }
    }
}

```

7. Save the file. If your project is installed in the web application format, rebuild the solution.

## Configuring Kentico to use Amazon CloudFront CDN

A Content Delivery Network (CDN) speeds up distribution of content to the end users through a network of data centers. See [What Is Amazon CloudFront?](http://docs.aws.amazon.com/general/latest/gr/docconventions.html) for details. To start using the Amazon CloudFront service with Kentico:

1. Create a **CloudFront Distribution**. You can use the [Amazon Management Console](https://console.aws.amazon.com/). Select your Amazon S3 storage bucket as the **Origin Domain Name**.
2. Open the **web.config** file of your Kentico project.
3. Add the **CMSAmazonPublicAccess** and **CMSAmazonEndPoint** keys into the web.config file:

   ```xml

   <appSettings>
       <add key="CMSAmazonPublicAccess" value="true" />
       <add key="CMSAmazonEndPoint" value="EndpointURL" />
   </appSettings>

   ```
4. Replace **EndpointURL** with the **Domain Name** URL from your created CDN.

   > **Note:** If your site runs under **HTTPS**, we recommend you always specify the **EndpointURL** with the **HTTPS** protocol as well.
   >
   > For example: https://domain.cloudfront.net
   >
   > Not doing so may result in [Mixed Content](https://developers.google.com/web/fundamentals/security/prevent-mixed-content/what-is-mixed-content?hl=en) warnings being logged in your web browser's console when retrieving files from the CDN.

Your project now uses the created CDN service.
