How To Use Amazon S3 For File Storage - Mura Docs v6

How To Use Amazon S3 For File Storage

If you haven't already done so, you will have to set up an Amazon S3 account. Then, follow the steps below to use Amazon S3 to store Mura CMS assets in the cloud.

Note: This is something you should set up before anyone has created any content in Mura. Also, these settings apply to all sites under the Mura CMS installation.

Create Amazon S3 Bucket

First, we need to create an Amazon S3 Bucket to store Mura CMS assets.

  1. Go to the S3 area of your Amazon console.
  2. Create a bucket to store your Mura CMS assets.
  3. Select the bucket, then click the "Properties" button.
  4. Then, click on "Permissions"
  5. Click "Add bucket policy"
  6. Using the "Bucket Policy Editor" you can use the sample policy below, or create your own. This is very important, because this policy will allow any assets within the bucket to be viewed on your website. Without this policy, you will get an "AccessDenied" message when attempting to access any assets anonymously.
     
    {
    "Id": "SampleMuraCMSPolicy",
    "Statement": [
    {
    "Sid": "ReadOnlyPermToAnonymousUser",
    "Action": "s3:GetObject",
    "Effect": "Allow",
    "Resource": "arn:aws:s3:::YourBucketName/*",
    "Principal": {
    "AWS": [
    "*"
    ]
    }
    },
    {
    "Sid": "RestrictAccessToSpecificHTTPReferrer",
    "Action": "s3:*",
    "Effect": "Allow",
    "Principal": {
    "AWS": [
    "*"
    ]
    },
    "Resource": "arn:aws:s3:::YourBucketName/*",
    "Condition": {
    "StringLike": {
    "aws:Referer": [
    "http://www.yourdomain.com/*",
    "http://yourdomain.com/*"
    ]
    }
    }
    }
    ]
    }
  7. Click "Save"

Congratulations! You have successfully created a bucket to store Mura CMS assets, and allow end users to view these assets with the blanket "Bucket Policy."

Create Amazon S3 User Account

Next, we need to create a special Amazon S3 User account for Mura CMS, and apply the appropriate "User Policy" so Mura will be able to create and modify assets in the bucket.

  1. Go to the IAM (Identity and Access Management) area of your Amazon console.
  2. Click on "Users" and then "Create New Users."
  3. Enter a User Name. Then click "Create."
  4. You should be on a screen that will allow you to view and download the credentials.
  5. You will need the Access Key ID and Secret Access Key information!
  6. When done, go back to the list of Users, and select the new user account you've created.
  7. You will now need to "Attach User Policy" so that this account can create, delete, and modify assets where needed. Here's a sample policy that essentially allows Mura CMS all access:
     
    {
    "Version": "2012-10-17",
    "Statement": [
    {
    "Effect": "Allow",
    "Action": "s3:*",
    "Resource": "*"
    }
    ]
    }
  8. You could also simply "Select Policy Template" and then scroll to the "Amazon S3 Full Access" policy, then click the "Select" button.
  9. Then, click "Apply Policy."

Well done! You have created a user account, with the permissions needed for Mura to add/modify assets on Amazon S3.

Create Mapped Drive to Amazon S3

This is a critical piece of the puzzle. You will most likely need to install some software that allows you to create a mapped drive on your server to your Amazon S3 account. There are several options available such as S3FS-FUSE (File System in User Space), TntDrive (Windows Only), and CloudBerry Drive Server (Windows Only).

For testing on your local machine, in addition to some of the options listed above, you could try something like ExpanDrive (available for Mac & Windows), which connects to several other cloud hosting services as well.

Once you've setup your mapping, you should then be ready to proceed.

Add Mapped Drive Info To Mura CMS

Finally, we need to add the drive mapping information so that Mura can locate, create and modify assets.

  1. Open the file located under {MuraRoot}/config/settings.ini.cfm
  2. Locate, and update the following settings as listed below with the credentials you obtained when creating the user acount above:

    {MuraRoot}/config/settings.ini.cfm

    filestore=fileDir
    filedir=/YourMappedDrive
    assetdir=/YourMappedDrive
    assetpath=http://yourbucketname.s3.amazonaws.com
    usefilemode=false
    defaultfilemode=777

    For example, if you're using ExpanDrive, with the following configuration:

    Your settings.ini.cfm file would look like this:

    filedir=/Volumes/foldername
    assetdir=/Volumes/foldername
    assetpath=http://bucketname.s3.amazonaws.com
  3. Go to the Mura CMS Administration area, and Reload Application for the settings to take effect.

You should now be able to test your setup by creating a Page, adding a Primary Associated Image, and adding an image to the Body area. Publish, then preview the content via the front end of your site.