Forum

Thread tagged as: Configuration, Addons

A few notes about Amazon s3 and Runway

Hey Drew, Rachel, and friends,

I'm using Perch runway 2.8.x, and I thought I would give you a heads up about my experience and pain points with Perch buckets and Amazon s3.

  • I needed to add a semicolon after the Perch bucket list array in /perch/config/buckets.php. That was a silly PHP oversight on my part, but I just copied the code from https://docs.grabaperch.com/runway/cloud-storage/amazon/, and after some head-banging (not the rock and roll kind) I realized that was missing. The debugger also didn't catch that error.
  • Perch doesn't seem to like s3 buckets with periods (or full domains, I'm not sure which). I changed my s3 bucket and Perch bucket names from www.example.com to www-example-com and that seemed to solve the problem.
  • s3 wants the endpoint to be https://bucket-name.s3.amazonaws.com, not https://s3.amazonaws.com/bucket-name. I think the former is the proper REST endpoint.
  • You can specify folders within an s3 bucket, rather than having to create separate s3 buckets for each Perch bucket! For example, for a Perch bucket, you can declare 'https://bucket-name.s3.amazonaws.com/images' as the web_path, and 'bucket-name/images' as the file_path. That way, you could keep all your resources for a Perch site in one s3 bucket, but still create multiple folders within that bucket.
  • There is some configuration required on s3. In addition to needing keys to connect Perch to AWS, to publicly access the s3 resources you have to add a CORS configuration and an s3 bucket policy allowing public access. There are tutorials on aws about how to do that, but my configuration ended up looking like this:

Bucket policy:

{
    "Version": "2008-10-17",
    "Statement": [
        {
            "Sid": "AllowPublicRead",
            "Effect": "Allow",
            "Principal": {
                "AWS": "*"
            },
            "Action": "s3:GetObject",
            "Resource": "arn:aws:s3:::bucket-name/*"
        }
    ]
}

And the CORS configuration:

<?xml version="1.0" encoding="UTF-8"?>
<CORSConfiguration xmlns="https://s3.amazonaws.com/doc/2006-03-01/">
    <CORSRule>
        <AllowedOrigin>https://localhost:3000</AllowedOrigin>
        <AllowedMethod>GET</AllowedMethod>
        <AllowedMethod>POST</AllowedMethod>
        <AllowedMethod>PUT</AllowedMethod>
        <AllowedHeader>*</AllowedHeader>
    </CORSRule>
</CORSConfiguration>

It's entirely possible that my experience doesn't reflect anyone else's, but this is what I had to do to get things going with s3 and Perch.

-Rob

Robert Yedlin

Robert Yedlin 1 points

  • 6 years ago
Drew McLellan

Drew McLellan 2638 points
Perch Support

Thanks Robert. Where was the semicolon missing?

The last line

<?php 
    return [
        'images' => [
                 'type'      => 'amazon_s3',
                 'web_path'  => '',
                 'file_path' => '',
         ],
    ];

And here:

<?php 
    return [
        'images' => [
                 'type'      => 'amazon_s3',
                 'web_path'  => 'https://s3.amazonaws.com/myproject.images',
                 'file_path' => 'myproject.images',
         ],
         'press_releases' => [
                  'type'      => 'amazon_s3',
                  'web_path'  => 'https://s3.amazonaws.com/myproject.press',
                  'file_path' => 'myproject.press',
          ],
    ];
Drew McLellan

Drew McLellan 2638 points
Perch Support

I guess so - thanks.