How to use Amazon S3 storage on Ghost

How to use Amazon S3 storage on Ghost

The idea to use Amazon S3 is to store all the images on it instead of storing them locally. Or in other words, the new images are going to be stored on Amazon S3 and not /content/images.

Requierements

1. You need to create a bucket in the Console if you don't have one yet.

Ghost Bucket

2. You also need the create a user with access to S3, it will provide two keys the access key ID and the secret access key, you can create a user in the Console.
Take note of both keys the most important is the secret key because it appears only one time after you create the user, the keys are used in the last step.

Ghost Keys

3. Take note about your bucket region since there are different endpoints you can detect the region in the properties tab:

Ghost Keys

Steps

The first step is to install a storage module (ghost-storage-adapter-s3), which is going to do all the work:

npm install ghost-storage-adapter-s3

Now you have the copy the module directly to your ghost project inside the content folder:

mkdir -p ./content/storage
cp -r ./node_modules/ghost-storage-adapter-s3 ./content/storage/s3

You are ready to configure the module, inside the file config.js you have to insert this lines inside the environment that you are using (production or development):

storage: {
  active: 's3',
  s3: {
    accessKeyId: 'YOUR_ACCESS_KEY_ID',
    assetHost: 'YOUR_OPTIONAL_CDN_URL',
    bucket: 'YOUR_BUCKET_NAME',
    pathPrefix: 'YOUR_OPTIONAL_BUCKET_SUBDIRECTORY',
    region: 'YOUR_REGION_SLUG',
    secretAccessKey: 'YOUR_SECRET_ACCESS_KEY'
  }
}
  • pathPrefix is the folder name where the images are going to be stored I used 'blog'.
  • assetHost is the URL that your bucket use for the file to be accessible on internet, for us-east-1 the URL is: https://s3.amazonaws.com/[your-bucket-name].