Configuring Amazon S3

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.

File name case

Unlike standard Windows file systems, the Amazon S3 storage is case-sensitive. To ensure consistent behavior, Xperience automatically converts all file and folder names to lower case when processing files on Amazon S3.

Mapping files to Amazon storage

Mapping folders to Amazon storage allows you to store large files (e.g., media library files) on a shared storage and leverage Amazon’s Cloudfront CDN.

Before you can begin mapping parts of the file system to Amazon storage, add the following keys to the web.config files of both the MVC and administration applications:

  1. Specify the ID of your Amazon access key:

    
    
    
     <add key="CMSAmazonAccessKeyID" value="YourKey" />
    
    
     
  2. Specify the Amazon access key:

    
    
    
     <add key="CMSAmazonAccessKey" value="YourSecret" />
    
    
     
  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.

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

Before you can begin mapping parts of the file system to Amazon storage, add the following keys to the web.config file of the administration application and the appsettings.json file of the Core application:

  1. Specify the ID of your Amazon access key:

    web.config
    
    
    
     <add key="CMSAmazonAccessKeyID" value="YourKey" />
    
    
     
    appsettings.json
    
    
    
     "CMSAmazonAccessKeyID": "YourKey"
    
    
     
  2. Specify the Amazon access key:

    web.config
    
    
    
     <add key="CMSAmazonAccessKey" value="YourSecret" />
    
    
     
    appsettings.json
    
    
    
     "CMSAmazonAccessKey": "YourSecret"
    
    
     
  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.

    web.config
    
    
    
     <add key="CMSAmazonBucketName"  value="YourBucketName" />
    
    
     
    appsettings.json
    
    
    
     "CMSAmazonBucketName": "YourBucketName"
    
    
     

With the Amazon account connected and configured, use the following process to map parts of the file system to the specified bucket:

  1. Open the Xperience solution in Visual Studio (using the WebApp.sln file).

  2. Create a custom module class. Add the class into a custom Class Library project within the solution.

    For basic execution of initialization code, you only need to register a “code-only” module through the API. You do NOT need to create a new module within the Modules application in the administration interface.

  3. Override the module’s OnInit method and perform the following:

    • 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.
    
    
    
     using CMS;
     using CMS.Base;
     using CMS.DataEngine;
     using CMS.IO;
    
     // Registers the custom module into the system
     [assembly: RegisterModule(typeof(CustomInitializationModule))]
    
     public class CustomInitializationModule : Module
     {
         // Module class constructor, the system registers the module under the name "CustomInit"
         public CustomInitializationModule()
             : base("CustomInit")
         {
         }
    
         // Contains initialization code that is executed when the application starts
         protected override void OnInit()
         {
             base.OnInit();
    
             // Creates a new StorageProvider instance for Amazon S3
             var mediaProvider = StorageProvider.CreateAmazonStorageProvider();
    
             // 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);
         }
     }
    
    
     
  4. Save the file and Rebuild the solution.

  5. Deploy the assembly containing the custom storage provider code to your separate live site application (in addition to the Xperience administration project).

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).

Also, see the Media library notes at the end of this page for additional information about specifics of media libraries when using Amazon S3 storage.

Additionally, you can configure the following optional settings. Note that the keys must be added to both the live site and administration applications:

Key

Description

CMSAmazonTempPath

Path to a local directory that the system uses to store temporary files.

Default value: <installation root>\CMS\App_Data\AmazonTemp

Sample custom value

web.config



<add key="CMSAmazonTempPath" value="C:\Windows\Temp" />


appsettings.json



"CMSAmazonTempPath": "C:\Windows\Temp"


CMSAmazonCachePath

Path to a local directory where the provider stores cached files.

Default value: <installation root>\CMS\App_Data\AmazonCache

Sample custom value

web.config



<add key="CMSAmazonCachePath" value="C:\Cache" />


appsettings.json



"CMSAmazonCachePath": "C:\Cache"


CMSAmazonEndPoint

Allows you to change the default URL of the Amazon S3 Website Endpoint. For example, you can change the endpoint if you want to use CloudFront CDN.

Default value: http://<yourbucketname>.s3.amazonaws.com

Sample custom value

web.config



<add key="CMSAmazonEndPoint" value="http://someendpoint.s3.amazonaws.com" />


appsettings.json



"CMSAmazonEndPoint": "http://someendpoint.s3.amazonaws.com"


CMSAmazonRestApiEndPoint

Allows you to change the default URL of the Amazon S3 REST API Endpoint. The system uses the REST API to determine the region of buckets.

Default value: https://s3.amazonaws.com

Sample custom value

web.config



<add key="CMSAmazonRestApiEndPoint" value="http://s3.amazonaws.com" />


appsettings.json



"CMSAmazonRestApiEndPoint": "http://s3.amazonaws.com"


CMSAmazonPublicAccess

Specifies whether files uploaded to Amazon S3 through Xperience are accessible for public users.

Default value:

true if you specify an endpoint

false If no endpoint is specified

Sample custom value

web.config



<add key="CMSAmazonPublicAccess" value="true"/> 


appsettings.json



"CMSAmazonPublicAccess": true 


Configuring Xperience 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 Amazon CloudFront Product Details to learn more.

To start using the Amazon CloudFront service with Xperience:

  1. Create a CloudFront Distribution. You can use the Amazon Management Console. Select your Amazon S3 storage bucket as the Origin Domain Name.

  2. Edit the web.config file of your Xperience project.

  3. Add the CMSAmazonPublicAccess and CMSAmazonEndPoint keys into the web.config files of both the MVC and administration applications:

    
    
    
     <appSettings>
         <add key="CMSAmazonPublicAccess" value="true" />
         <add key="CMSAmazonEndPoint" value="EndpointURL" />
     </appSettings>
    
    
     
  4. Set the value of the CMSAmazonEndPoint key to the Domain Name URL of your created CDN.

    If your site runs under HTTPS, we recommend always specifying the endpoint URL with the HTTPS protocol as well.

    For example: https://domain.cloudfront.net

    Without this configure you may receive Mixed Content warnings in your browser’s console when retrieving files from the CDN.

To start using the Amazon CloudFront service with Xperience:

  1. Create a CloudFront Distribution. You can use the Amazon Management Console. Select your Amazon S3 storage bucket as the Origin Domain Name.

  2. Edit the web.config file of your Xperience project.

  3. Add the CMSAmazonPublicAccess and CMSAmazonEndPoint keys into the web.config file of the administration application and the appsettings.json file of your Core live site application:

    web.config
    
    
    
     <appSettings>
         <add key="CMSAmazonPublicAccess" value="true" />
         <add key="CMSAmazonEndPoint" value="EndpointURL" />
     </appSettings>
    
    
     
    appsettings.json
    
    
    
     "CMSAmazonPublicAccess": true,
     "CMSAmazonEndPoint": "EndpointURL"
    
    
     
  4. Set the value of the CMSAmazonEndPoint key to the Domain Name URL of your created CDN.

    If your site runs under HTTPS, we recommend always specifying the endpoint URL with the HTTPS protocol as well.

    For example: https://domain.cloudfront.net

    Without this configure you may receive Mixed Content warnings in your browser’s console when retrieving files from the CDN.

Your project now starts using the created CDN service.

Media library notes

Using Amazon S3 storage for your project has some effects on media libraries.

Storing too many files in one media library folder

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 for details.

Use the same bucket when CMSAmazonPublicAccess is set to true

If all of the following conditions are true:

  • you use Amazon S3 as external storage
  • you set the CMSAmazonPublicAccess key to true
  • you want to use content staging

then you need to use the same bucket across all instances in your staging topology. The system uses the bucket name in the URLs of media file links. If an instance in the staging topology uses a different bucket (via the CMSAmazonBucketName key), links to media files placed within staged content may not get resolved correctly.