Logo Mark

Backup Destinations

AWS

A guide on how to set up AWS as a cloud destination for Craft Remote Backup


Overview

S3 is moderately easy to set up. You need to create an AWS account then create a new S3 bucket. Finally you need to create a user that has programmatic access to that bucket and use the access credentials of that user to connect via Remote Backup.

Setup

To use S3 first install the official AWS PHP SDK:

composer require aws/aws-sdk-php:^3

Configure AWS

Login to your AWS console via and go to S3. Create a new bucket:

Make sure you remember the name (in this case craft-remote-backups - bear in mind this needs to be globally unique) and also make sure to "block all public access".

You need to also note the region the bucket is in. An easy way to do this is to get it from the URL when viewing the bucket:

Next search "IAM" in the services tab at the top. From the IAM dashboard go to "users" in the sidebar:

Then go to "add user":

Give the user a name (craft-backups) and make sure to tick "Programmatic access".

On the next page, click the "Attach existing policies directly" tab:

This will open a new window. Hit the "create policy" button:

Now enter the following text. Make sure to update the bucket name at the bottom if you've got a different name to craft-remote-backups

{
  "Version": "2012-10-17",
  "Statement": [
    {
      "Sid": "VisualEditor1",
      "Effect": "Allow",
      "Action": "s3:*",
      "Resource": [
        "arn:aws:s3:::craft-remote-backups",
        "arn:aws:s3:::craft-remote-backups/*"
      ]
    }
  ]
}

Click save down the bottom and give the policy a new name (craft-backups):

Go back to the original window, refresh the contents of the page and search for your new policy. Select it and hit next down the bottom:

You can skip over the tags page, then save the new user.

Once saved, save your "access key id" and "secret access key" as you will need these in the next step:

Configure Remote Backup

We now need to add the credentials to our Craft project. The best way to do this is to create some environment variables in our Craft project's .env file:

AWS_ACCESS_KEY = "..."
AWS_SECRET_KEY = "..."
AWS_REGION = "us-west-1"
AWS_BUCKET_NAME = "craft-remote-backups"
AWS_BUCKET_PATH = "project-xyz"

Now go to the Remote Backup settings page in the Control Panel and save these variables:

You should now be able to create new backups.

Optional Bucket Folder Path

You can add an optional folder path within your bucket to save backups. Make sure the path doesn't beging or end with a slash and also only contains letters, numbers and -/_:

Valid examples:

  • project-xyz/backups
  • my-backups

Invalid example:

  • Project XYZ/backups
  • /project-xyz/backups
  • /my-backups
  • my-backups/

Troubleshooting

If you are encountering errors, first check your credentials. After that, have a look in storage/logs/web.log for errors. Usually these issues are related to credentials or folder paths. If you're still having trouble, see the troubleshooting section.

Previous
Configuration